Skip to content

Commit 9087da2

Browse files
authored
Merge pull request #7268 from bshaffer/patch-2
PHP: Adds "finally", "fn", "match", and "yield" to reserved names
2 parents 336ed18 + d995c1c commit 9087da2

File tree

9 files changed

+216
-169
lines changed

9 files changed

+216
-169
lines changed

php/ext/google/protobuf/names.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,22 @@ static void stringsink_uninit(stringsink *sink) { free(sink->ptr); }
7171
/* def name -> classname ******************************************************/
7272

7373
const char *const kReservedNames[] = {
74-
"abstract", "and", "array", "as", "break",
75-
"callable", "case", "catch", "class", "clone",
76-
"const", "continue", "declare", "default", "die",
77-
"do", "echo", "else", "elseif", "empty",
78-
"enddeclare", "endfor", "endforeach", "endif", "endswitch",
79-
"endwhile", "eval", "exit", "extends", "final",
80-
"for", "foreach", "function", "global", "goto",
81-
"if", "implements", "include", "include_once", "instanceof",
82-
"insteadof", "interface", "isset", "list", "namespace",
83-
"new", "or", "print", "private", "protected",
84-
"public", "require", "require_once", "return", "static",
85-
"switch", "throw", "trait", "try", "unset",
86-
"use", "var", "while", "xor", "int",
87-
"float", "bool", "string", "true", "false",
88-
"null", "void", "iterable", NULL};
74+
"abstract", "and", "array", "as", "break",
75+
"callable", "case", "catch", "class", "clone",
76+
"const", "continue", "declare", "default", "die",
77+
"do", "echo", "else", "elseif", "empty",
78+
"enddeclare", "endfor", "endforeach", "endif", "endswitch",
79+
"endwhile", "eval", "exit", "extends", "final",
80+
"finally", "fn" "for", "foreach", "function",
81+
"if", "implements", "include", "include_once", "instanceof",
82+
"global", "goto", "insteadof", "interface", "isset",
83+
"list", "match", "namespace", "new", "or",
84+
"print", "private", "protected", "public", "require",
85+
"require_once", "return", "static", "switch", "throw",
86+
"trait", "try", "unset", "use", "var",
87+
"while", "xor", "yield", "int", "float",
88+
"bool", "string", "true", "false", "null",
89+
"void", "iterable", NULL};
8990

9091
bool is_reserved_name(const char* name) {
9192
int i;

php/src/Google/Protobuf/Internal/GPBUtil.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,16 @@ public static function getClassNamePrefix(
279279
"do"=>0, "echo"=>0, "else"=>0, "elseif"=>0, "empty"=>0,
280280
"enddeclare"=>0, "endfor"=>0, "endforeach"=>0, "endif"=>0,
281281
"endswitch"=>0, "endwhile"=>0, "eval"=>0, "exit"=>0, "extends"=>0,
282-
"final"=>0, "for"=>0, "foreach"=>0, "function"=>0, "global"=>0,
283-
"goto"=>0, "if"=>0, "implements"=>0, "include"=>0,
284-
"include_once"=>0, "instanceof"=>0, "insteadof"=>0, "interface"=>0,
285-
"isset"=>0, "list"=>0, "namespace"=>0, "new"=>0, "or"=>0,
286-
"print"=>0, "private"=>0, "protected"=>0, "public"=>0, "require"=>0,
287-
"require_once"=>0, "return"=>0, "static"=>0, "switch"=>0,
288-
"throw"=>0, "trait"=>0, "try"=>0, "unset"=>0, "use"=>0, "var"=>0,
289-
"while"=>0, "xor"=>0, "int"=>0, "float"=>0, "bool"=>0, "string"=>0,
290-
"true"=>0, "false"=>0, "null"=>0, "void"=>0, "iterable"=>0
282+
"final"=>0, "finally"=>0, "fn"=>0, "for"=>0, "foreach"=>0,
283+
"function"=>0, "global"=>0, "goto"=>0, "if"=>0, "implements"=>0,
284+
"include"=>0, "include_once"=>0, "instanceof"=>0, "insteadof"=>0,
285+
"interface"=>0, "isset"=>0, "list"=>0, "match"=>0, "namespace"=>0,
286+
"new"=>0, "or"=>0, "print"=>0, "private"=>0, "protected"=>0,
287+
"public"=>0, "require"=>0, "require_once"=>0, "return"=>0,
288+
"static"=>0, "switch"=>0, "throw"=>0, "trait"=>0, "try"=>0,
289+
"unset"=>0, "use"=>0, "var"=>0, "while"=>0, "xor"=>0, "yield"=>0,
290+
"int"=>0, "float"=>0, "bool"=>0, "string"=>0, "true"=>0, "false"=>0,
291+
"null"=>0, "void"=>0, "iterable"=>0
291292
);
292293

293294
if (array_key_exists(strtolower($classname), $reserved_words)) {

php/tests/GeneratedClassTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,8 @@ public function testPrefixForReservedWords()
913913
$m = new \Lower\PBexit();
914914
$m = new \Lower\PBextends();
915915
$m = new \Lower\PBfinal();
916+
$m = new \Lower\PBfinally();
917+
$m = new \Lower\PBfn();
916918
$m = new \Lower\PBfor();
917919
$m = new \Lower\PBforeach();
918920
$m = new \Lower\PBfunction();
@@ -927,6 +929,7 @@ public function testPrefixForReservedWords()
927929
$m = new \Lower\PBinterface();
928930
$m = new \Lower\PBisset();
929931
$m = new \Lower\PBlist();
932+
$m = new \Lower\PBmatch();
930933
$m = new \Lower\PBnamespace();
931934
$m = new \Lower\PBnew();
932935
$m = new \Lower\PBor();
@@ -947,6 +950,7 @@ public function testPrefixForReservedWords()
947950
$m = new \Lower\PBvar();
948951
$m = new \Lower\PBwhile();
949952
$m = new \Lower\PBxor();
953+
$m = new \Lower\PByield();
950954
$m = new \Lower\PBint();
951955
$m = new \Lower\PBfloat();
952956
$m = new \Lower\PBbool();
@@ -987,6 +991,8 @@ public function testPrefixForReservedWords()
987991
$m = new \Upper\PBEXIT();
988992
$m = new \Upper\PBEXTENDS();
989993
$m = new \Upper\PBFINAL();
994+
$m = new \Upper\PBFINALLY();
995+
$m = new \Upper\PBFN();
990996
$m = new \Upper\PBFOR();
991997
$m = new \Upper\PBFOREACH();
992998
$m = new \Upper\PBFUNCTION();
@@ -1001,6 +1007,7 @@ public function testPrefixForReservedWords()
10011007
$m = new \Upper\PBINTERFACE();
10021008
$m = new \Upper\PBISSET();
10031009
$m = new \Upper\PBLIST();
1010+
$m = new \Upper\PBMATCH();
10041011
$m = new \Upper\PBNAMESPACE();
10051012
$m = new \Upper\PBNEW();
10061013
$m = new \Upper\PBOR();
@@ -1021,6 +1028,7 @@ public function testPrefixForReservedWords()
10211028
$m = new \Upper\PBVAR();
10221029
$m = new \Upper\PBWHILE();
10231030
$m = new \Upper\PBXOR();
1031+
$m = new \Upper\PBYIELD();
10241032
$m = new \Upper\PBINT();
10251033
$m = new \Upper\PBFLOAT();
10261034
$m = new \Upper\PBBOOL();
@@ -1061,6 +1069,8 @@ public function testPrefixForReservedWords()
10611069
$m = new \Lower_enum\PBexit();
10621070
$m = new \Lower_enum\PBextends();
10631071
$m = new \Lower_enum\PBfinal();
1072+
$m = new \Lower_enum\PBfinally();
1073+
$m = new \Lower_enum\PBfn();
10641074
$m = new \Lower_enum\PBfor();
10651075
$m = new \Lower_enum\PBforeach();
10661076
$m = new \Lower_enum\PBfunction();
@@ -1075,6 +1085,7 @@ public function testPrefixForReservedWords()
10751085
$m = new \Lower_enum\PBinterface();
10761086
$m = new \Lower_enum\PBisset();
10771087
$m = new \Lower_enum\PBlist();
1088+
$m = new \Lower_enum\PBmatch();
10781089
$m = new \Lower_enum\PBnamespace();
10791090
$m = new \Lower_enum\PBnew();
10801091
$m = new \Lower_enum\PBor();
@@ -1095,6 +1106,7 @@ public function testPrefixForReservedWords()
10951106
$m = new \Lower_enum\PBvar();
10961107
$m = new \Lower_enum\PBwhile();
10971108
$m = new \Lower_enum\PBxor();
1109+
$m = new \Lower_enum\PByield();
10981110
$m = new \Lower_enum\PBint();
10991111
$m = new \Lower_enum\PBfloat();
11001112
$m = new \Lower_enum\PBbool();
@@ -1135,6 +1147,8 @@ public function testPrefixForReservedWords()
11351147
$m = new \Upper_enum\PBEXIT();
11361148
$m = new \Upper_enum\PBEXTENDS();
11371149
$m = new \Upper_enum\PBFINAL();
1150+
$m = new \Upper_enum\PBFINALLY();
1151+
$m = new \Upper_enum\PBFN();
11381152
$m = new \Upper_enum\PBFOR();
11391153
$m = new \Upper_enum\PBFOREACH();
11401154
$m = new \Upper_enum\PBFUNCTION();
@@ -1149,6 +1163,7 @@ public function testPrefixForReservedWords()
11491163
$m = new \Upper_enum\PBINTERFACE();
11501164
$m = new \Upper_enum\PBISSET();
11511165
$m = new \Upper_enum\PBLIST();
1166+
$m = new \Upper_enum\PBMATCH();
11521167
$m = new \Upper_enum\PBNAMESPACE();
11531168
$m = new \Upper_enum\PBNEW();
11541169
$m = new \Upper_enum\PBOR();
@@ -1169,6 +1184,7 @@ public function testPrefixForReservedWords()
11691184
$m = new \Upper_enum\PBVAR();
11701185
$m = new \Upper_enum\PBWHILE();
11711186
$m = new \Upper_enum\PBXOR();
1187+
$m = new \Upper_enum\PBYIELD();
11721188
$m = new \Upper_enum\PBINT();
11731189
$m = new \Upper_enum\PBFLOAT();
11741190
$m = new \Upper_enum\PBBOOL();
@@ -1209,6 +1225,8 @@ public function testPrefixForReservedWords()
12091225
$m = \Lower_enum_value\NotAllowed::PBexit;
12101226
$m = \Lower_enum_value\NotAllowed::PBextends;
12111227
$m = \Lower_enum_value\NotAllowed::PBfinal;
1228+
$m = \Lower_enum_value\NotAllowed::PBfinally;
1229+
$m = \Lower_enum_value\NotAllowed::PBfn;
12121230
$m = \Lower_enum_value\NotAllowed::PBfor;
12131231
$m = \Lower_enum_value\NotAllowed::PBforeach;
12141232
$m = \Lower_enum_value\NotAllowed::PBfunction;
@@ -1223,6 +1241,7 @@ public function testPrefixForReservedWords()
12231241
$m = \Lower_enum_value\NotAllowed::PBinterface;
12241242
$m = \Lower_enum_value\NotAllowed::PBisset;
12251243
$m = \Lower_enum_value\NotAllowed::PBlist;
1244+
$m = \Lower_enum_value\NotAllowed::PBmatch;
12261245
$m = \Lower_enum_value\NotAllowed::PBnamespace;
12271246
$m = \Lower_enum_value\NotAllowed::PBnew;
12281247
$m = \Lower_enum_value\NotAllowed::PBor;
@@ -1243,6 +1262,7 @@ public function testPrefixForReservedWords()
12431262
$m = \Lower_enum_value\NotAllowed::PBvar;
12441263
$m = \Lower_enum_value\NotAllowed::PBwhile;
12451264
$m = \Lower_enum_value\NotAllowed::PBxor;
1265+
$m = \Lower_enum_value\NotAllowed::PByield;
12461266
$m = \Lower_enum_value\NotAllowed::int;
12471267
$m = \Lower_enum_value\NotAllowed::float;
12481268
$m = \Lower_enum_value\NotAllowed::bool;
@@ -1283,6 +1303,8 @@ public function testPrefixForReservedWords()
12831303
$m = \Upper_enum_value\NotAllowed::PBEXIT;
12841304
$m = \Upper_enum_value\NotAllowed::PBEXTENDS;
12851305
$m = \Upper_enum_value\NotAllowed::PBFINAL;
1306+
$m = \Upper_enum_value\NotAllowed::PBFINALLY;
1307+
$m = \Upper_enum_value\NotAllowed::PBFN;
12861308
$m = \Upper_enum_value\NotAllowed::PBFOR;
12871309
$m = \Upper_enum_value\NotAllowed::PBFOREACH;
12881310
$m = \Upper_enum_value\NotAllowed::PBFUNCTION;
@@ -1297,6 +1319,7 @@ public function testPrefixForReservedWords()
12971319
$m = \Upper_enum_value\NotAllowed::PBINTERFACE;
12981320
$m = \Upper_enum_value\NotAllowed::PBISSET;
12991321
$m = \Upper_enum_value\NotAllowed::PBLIST;
1322+
$m = \Upper_enum_value\NotAllowed::PBMATCH;
13001323
$m = \Upper_enum_value\NotAllowed::PBNAMESPACE;
13011324
$m = \Upper_enum_value\NotAllowed::PBNEW;
13021325
$m = \Upper_enum_value\NotAllowed::PBOR;
@@ -1317,6 +1340,7 @@ public function testPrefixForReservedWords()
13171340
$m = \Upper_enum_value\NotAllowed::PBVAR;
13181341
$m = \Upper_enum_value\NotAllowed::PBWHILE;
13191342
$m = \Upper_enum_value\NotAllowed::PBXOR;
1343+
$m = \Upper_enum_value\NotAllowed::PBYIELD;
13201344
$m = \Upper_enum_value\NotAllowed::INT;
13211345
$m = \Upper_enum_value\NotAllowed::FLOAT;
13221346
$m = \Upper_enum_value\NotAllowed::BOOL;

php/tests/proto/test_reserved_enum_lower.proto

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,50 @@ enum eval { ZERO27 = 0; }
3232
enum exit { ZERO28 = 0; }
3333
enum extends { ZERO29 = 0; }
3434
enum final { ZERO30 = 0; }
35-
enum for { ZERO31 = 0; }
36-
enum foreach { ZERO32 = 0; }
37-
enum function { ZERO33 = 0; }
38-
enum global { ZERO34 = 0; }
39-
enum goto { ZERO35 = 0; }
40-
enum if { ZERO36 = 0; }
41-
enum implements { ZERO37 = 0; }
42-
enum include { ZERO38 = 0; }
43-
enum include_once { ZERO39 = 0; }
44-
enum instanceof { ZERO40 = 0; }
45-
enum insteadof { ZERO41 = 0; }
46-
enum interface { ZERO42 = 0; }
47-
enum isset { ZERO43 = 0; }
48-
enum list { ZERO44 = 0; }
49-
enum namespace { ZERO45 = 0; }
50-
enum new { ZERO46 = 0; }
51-
enum or { ZERO47 = 0; }
52-
enum print { ZERO48 = 0; }
53-
enum private { ZERO49 = 0; }
54-
enum protected { ZERO50 = 0; }
55-
enum public { ZERO51 = 0; }
56-
enum require { ZERO52 = 0; }
57-
enum require_once { ZERO53 = 0; }
58-
enum return { ZERO54 = 0; }
59-
enum static { ZERO55 = 0; }
60-
enum switch { ZERO56 = 0; }
61-
enum throw { ZERO57 = 0; }
62-
enum trait { ZERO58 = 0; }
63-
enum try { ZERO59 = 0; }
64-
enum unset { ZERO60 = 0; }
65-
enum use { ZERO61 = 0; }
66-
enum var { ZERO62 = 0; }
67-
enum while { ZERO63 = 0; }
68-
enum xor { ZERO64 = 0; }
69-
enum int { ZERO65 = 0; }
70-
enum float { ZERO66 = 0; }
71-
enum bool { ZERO67 = 0; }
72-
enum string { ZERO68 = 0; }
73-
enum true { ZERO69 = 0; }
74-
enum false { ZERO70 = 0; }
75-
enum null { ZERO71 = 0; }
76-
enum void { ZERO72 = 0; }
77-
enum iterable { ZERO73 = 0; }
35+
enum finally { ZERO31 = 0; }
36+
enum fn { ZERO32 = 0; }
37+
enum for { ZERO33 = 0; }
38+
enum foreach { ZERO34 = 0; }
39+
enum function { ZERO35 = 0; }
40+
enum global { ZERO36 = 0; }
41+
enum goto { ZERO37 = 0; }
42+
enum if { ZERO38 = 0; }
43+
enum implements { ZERO39 = 0; }
44+
enum include { ZERO40 = 0; }
45+
enum include_once { ZERO41 = 0; }
46+
enum instanceof { ZERO42 = 0; }
47+
enum insteadof { ZERO43 = 0; }
48+
enum interface { ZERO44 = 0; }
49+
enum isset { ZERO45 = 0; }
50+
enum list { ZERO46 = 0; }
51+
enum match { ZERO47 = 0; }
52+
enum namespace { ZERO48 = 0; }
53+
enum new { ZERO49 = 0; }
54+
enum or { ZERO50 = 0; }
55+
enum print { ZERO51 = 0; }
56+
enum private { ZERO52 = 0; }
57+
enum protected { ZERO53 = 0; }
58+
enum public { ZERO54 = 0; }
59+
enum require { ZERO55 = 0; }
60+
enum require_once { ZERO56 = 0; }
61+
enum return { ZERO57 = 0; }
62+
enum static { ZERO58 = 0; }
63+
enum switch { ZERO59 = 0; }
64+
enum throw { ZERO60 = 0; }
65+
enum trait { ZERO61 = 0; }
66+
enum try { ZERO62 = 0; }
67+
enum unset { ZERO63 = 0; }
68+
enum use { ZERO64 = 0; }
69+
enum var { ZERO65 = 0; }
70+
enum while { ZERO66 = 0; }
71+
enum xor { ZERO67 = 0; }
72+
enum yield { ZERO68 = 0; }
73+
enum int { ZERO69 = 0; }
74+
enum float { ZERO70 = 0; }
75+
enum bool { ZERO71 = 0; }
76+
enum string { ZERO72 = 0; }
77+
enum true { ZERO73 = 0; }
78+
enum false { ZERO74 = 0; }
79+
enum null { ZERO75 = 0; }
80+
enum void { ZERO76 = 0; }
81+
enum iterable { ZERO77 = 0; }

0 commit comments

Comments
 (0)