]> granicus.if.org Git - php/commitdiff
- Fixed bug #53305 (E_NOTICE when defining a constant starts with __COMPILER_HALT_OF...
authorFelipe Pena <felipe@php.net>
Sat, 13 Nov 2010 18:46:11 +0000 (18:46 +0000)
committerFelipe Pena <felipe@php.net>
Sat, 13 Nov 2010 18:46:11 +0000 (18:46 +0000)
- Fixed a part of bug #53260 (the __COMPILER_HALT_OFFSET__ name is not shown in the E_NOTICE)

Zend/tests/bug53305.phpt [new file with mode: 0644]
Zend/zend_constants.c

diff --git a/Zend/tests/bug53305.phpt b/Zend/tests/bug53305.phpt
new file mode 100644 (file)
index 0000000..c922ac6
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Bug #53305 (E_NOTICE when defining a constant starts with __COMPILER_HALT_OFFSET__)
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+define('__COMPILER_HALT_OFFSET__1', 1);
+define('__COMPILER_HALT_OFFSET__2', 2);
+define('__COMPILER_HALT_OFFSET__', 3);
+define('__COMPILER_HALT_OFFSET__1'.chr(0), 4);
+
+var_dump(__COMPILER_HALT_OFFSET__1);
+var_dump(constant('__COMPILER_HALT_OFFSET__1'.chr(0)));
+
+?>
+--EXPECTF--
+Notice: Constant __COMPILER_HALT_OFFSET__ already defined in %s on line %d
+int(1)
+int(4)
index 04452e40dd4bcd18054770d8ba476e1ab1eebdb6..b566146af094472273e48d588e3f4d401c706a7d 100644 (file)
@@ -473,8 +473,15 @@ ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
                }
        }
 
-       if ((strncmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1) == 0) ||
-                       zend_hash_add(EG(zend_constants), name, c->name_len, (void *) c, sizeof(zend_constant), NULL)==FAILURE) {
+       /* Check if the user is trying to define the internal pseudo constant name __COMPILER_HALT_OFFSET__ */
+       if ((c->name_len == sizeof("__COMPILER_HALT_OFFSET__")
+               && !memcmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1))
+               || zend_hash_add(EG(zend_constants), name, c->name_len, (void *) c, sizeof(zend_constant), NULL)==FAILURE) {
+               
+               /* The internal __COMPILER_HALT_OFFSET__ is prefixed by NULL byte */
+               if (strncmp(name+1, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")) == 0) {
+                       name++;
+               }
                zend_error(E_NOTICE,"Constant %s already defined", name);
                str_free(c->name);
                if (!(c->flags & CONST_PERSISTENT)) {