aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/php
diff options
context:
space:
mode:
authorGravatar Bo Yang <teboring@google.com>2017-09-08 15:11:49 -0700
committerGravatar Bo Yang <teboring@google.com>2017-09-08 15:17:36 -0700
commite5d000cbb7bcf8fadddfbdb544070e31ce36fa26 (patch)
treea2ee22257bb80c1c213913959b4f24e7cd80acd6 /src/google/protobuf/compiler/php
parent6a4ffb2f90ef7bbd3f20f2a1db4948630ad37dc8 (diff)
Add prefix to php reserved keywords.
Diffstat (limited to 'src/google/protobuf/compiler/php')
-rw-r--r--src/google/protobuf/compiler/php/php_generator.cc24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc
index 60e6fce9..fe781df2 100644
--- a/src/google/protobuf/compiler/php/php_generator.cc
+++ b/src/google/protobuf/compiler/php/php_generator.cc
@@ -49,8 +49,23 @@ const std::string kDescriptorMetadataFile =
"GPBMetadata/Google/Protobuf/Internal/Descriptor.php";
const std::string kDescriptorDirName = "Google/Protobuf/Internal";
const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal";
-const char* const kReservedNames[] = {"ARRAY", "Empty", "ECHO"};
-const int kReservedNamesSize = 3;
+const char* const kReservedNames[] = {
+ "abstract", "and", "array", "as", "break",
+ "callable", "case", "catch", "class", "clone",
+ "const", "continue", "declare", "default", "die",
+ "do", "echo", "else", "elseif", "empty",
+ "enddeclare", "endfor", "endforeach", "endif", "endswitch",
+ "endwhile", "eval", "exit", "extends", "final",
+ "for", "foreach", "function", "global", "goto",
+ "if", "implements", "include", "include_once", "instanceof",
+ "insteadof", "interface", "isset", "list", "namespace",
+ "new", "or", "print", "private", "protected",
+ "public", "require", "require_once", "return", "static",
+ "switch", "throw", "trait", "try", "unset",
+ "use", "var", "while", "xor", "int",
+ "float", "bool", "string", "true", "false",
+ "null", "void", "iterable"};
+const int kReservedNamesSize = 73;
const int kFieldSetter = 1;
const int kFieldGetter = 2;
const int kFieldProperty = 3;
@@ -125,8 +140,11 @@ std::string ClassNamePrefix(const string& classname,
bool is_reserved = false;
+ string lower = classname;
+ transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
+
for (int i = 0; i < kReservedNamesSize; i++) {
- if (classname == kReservedNames[i]) {
+ if (lower == kReservedNames[i]) {
is_reserved = true;
break;
}