aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/ext
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 /php/ext
parent6a4ffb2f90ef7bbd3f20f2a1db4948630ad37dc8 (diff)
Add prefix to php reserved keywords.
Diffstat (limited to 'php/ext')
-rw-r--r--php/ext/google/protobuf/def.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c
index f885c145..d615cb3c 100644
--- a/php/ext/google/protobuf/def.c
+++ b/php/ext/google/protobuf/def.c
@@ -30,8 +30,23 @@
#include "protobuf.h"
-const char* const kReservedNames[] = {"Empty", "ECHO", "ARRAY"};
-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;
// Forward declare.
static void descriptor_init_c_instance(Descriptor* intern TSRMLS_DC);
@@ -774,12 +789,21 @@ static const char *classname_prefix(const char *classname,
return prefix_given;
}
+ char* lower = ALLOC_N(char, strlen(classname) + 1);
+ i = 0;
+ while(classname[i]) {
+ lower[i] = (char)tolower(classname[i]);
+ i++;
+ }
+ lower[i] = 0;
+
for (i = 0; i < kReservedNamesSize; i++) {
- if (strcmp(kReservedNames[i], classname) == 0) {
+ if (strcmp(kReservedNames[i], lower) == 0) {
is_reserved = true;
break;
}
}
+ FREE(lower);
if (is_reserved) {
if (package_name != NULL && strcmp("google.protobuf", package_name) == 0) {