]> granicus.if.org Git - php/commitdiff
Allow empty property names
authorNikita Popov <nikic@php.net>
Wed, 23 Mar 2016 17:57:59 +0000 (18:57 +0100)
committerNikita Popov <nikic@php.net>
Tue, 24 May 2016 16:34:17 +0000 (18:34 +0200)
Conflicts:
Zend/zend_compile.c

Zend/tests/bug29015.phpt
Zend/tests/bug52484.phpt
Zend/tests/bug52484_2.phpt
Zend/tests/bug52484_3.phpt
Zend/zend_object_handlers.c

index a36ed923f329077832217651de384dcd2b9871f2..d4231d10b1620d915f72fd83b685c6c2c22dee07 100644 (file)
@@ -6,9 +6,16 @@ $a = new stdClass();
 $x = "";
 $a->$x = "string('')";
 var_dump($a);
+$a->{"\0"} = 42;
+var_dump($a);
 ?>
 --EXPECTF--
-Fatal error: Uncaught Error: Cannot access empty property in %sbug29015.php:4
+object(stdClass)#1 (1) {
+  [""]=>
+  string(10) "string('')"
+}
+
+Fatal error: Uncaught Error: Cannot access property started with '\0' in %s:%d
 Stack trace:
 #0 {main}
-  thrown in %sbug29015.php on line 4
+  thrown in %s on line %d
index 053529614dc672fb01caedebc77b4d742b625839..1d2c2d7cdcc2573085c8cd96d2b3ae95beeb6ff0 100644 (file)
@@ -10,14 +10,14 @@ class A {
 }
 
 $a = new A();
-$prop = null;
+$prop = "\0";
 
 unset($a->$prop);
 
 ?>
 --EXPECTF--
-Fatal error: Uncaught Error: Cannot access empty property in %s:%d
+Fatal error: Uncaught Error: Cannot access property started with '\0' in %s:%d
 Stack trace:
-#0 %s(%d): A->__unset('')
+#0 %s(%d): A->__unset('\x00')
 #1 {main}
   thrown in %s on line %d
index 6bb927535ceaa9fead132d8970e658a132040d65..3b12950c66895448b6ec1a6609b5c91424e53093 100644 (file)
@@ -10,14 +10,14 @@ class A {
 }
 
 $a = new A();
-$prop = null;
+$prop = "\0";
 
 $a->$prop = 2;
 
 ?>
 --EXPECTF--
-Fatal error: Uncaught Error: Cannot access empty property in %s:%d
+Fatal error: Uncaught Error: Cannot access property started with '\0' in %s:%d
 Stack trace:
-#0 %s(%d): A->__set('', 2)
+#0 %s(%d): A->__set('\x00', 2)
 #1 {main}
   thrown in %s on line %d
index af32bc9be7a6af879e1b8e6998dd2c90ebf70b33..408dd453fd64caa61dd9f4dc210220f920a100fc 100644 (file)
@@ -10,14 +10,14 @@ class A {
 }
 
 $a = new A();
-$prop = null;
+$prop = "\0";
 
 var_dump($a->$prop);
 
 ?>
 --EXPECTF--
-Fatal error: Uncaught Error: Cannot access empty property in %s:%d
+Fatal error: Uncaught Error: Cannot access property started with '\0' in %s:%d
 Stack trace:
-#0 %s(%d): A->__get('')
+#0 %s(%d): A->__get('\x00')
 #1 {main}
   thrown in %s on line %d
index 6aa5d731c5b6f2257a0b991e28b142291b6581c3..d95f5d9a3346ee4effec5e0288f09f37ad87c0ed 100644 (file)
@@ -339,13 +339,9 @@ static zend_always_inline uint32_t zend_get_property_offset(zend_class_entry *ce
                return (uint32_t)(intptr_t)CACHED_PTR_EX(cache_slot + 1);
        }
 
-       if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0')) {
+       if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0' && ZSTR_LEN(member) != 0)) {
                if (!silent) {
-                       if (ZSTR_LEN(member) == 0) {
-                               zend_throw_error(NULL, "Cannot access empty property");
-                       } else {
-                               zend_throw_error(NULL, "Cannot access property started with '\\0'");
-                       }
+                       zend_throw_error(NULL, "Cannot access property started with '\\0'");
                }
                return ZEND_WRONG_PROPERTY_OFFSET;
        }
@@ -424,13 +420,9 @@ ZEND_API zend_property_info *zend_get_property_info(zend_class_entry *ce, zend_s
        uint32_t flags;
        zend_class_entry *scope;
 
-       if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0')) {
+       if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0' && ZSTR_LEN(member) != 0)) {
                if (!silent) {
-                       if (ZSTR_LEN(member) == 0) {
-                               zend_throw_error(NULL, "Cannot access empty property");
-                       } else {
-                               zend_throw_error(NULL, "Cannot access property started with '\\0'");
-                       }
+                       zend_throw_error(NULL, "Cannot access property started with '\\0'");
                }
                return ZEND_WRONG_PROPERTY_INFO;
        }
@@ -679,16 +671,10 @@ zval *zend_std_read_property(zval *object, zval *member, int type, void **cache_
                        zval_ptr_dtor(&tmp_object);
                        goto exit;
                } else {
-                       if (Z_STRVAL_P(member)[0] == '\0') {
-                               if (Z_STRLEN_P(member) == 0) {
-                                       zend_throw_error(NULL, "Cannot access empty property");
-                                       retval = &EG(uninitialized_zval);
-                                       goto exit;
-                               } else {
-                                       zend_throw_error(NULL, "Cannot access property started with '\\0'");
-                                       retval = &EG(uninitialized_zval);
-                                       goto exit;
-                               }
+                       if (Z_STRVAL_P(member)[0] == '\0' && Z_STRLEN_P(member) != 0) {
+                               zend_throw_error(NULL, "Cannot access property started with '\\0'");
+                               retval = &EG(uninitialized_zval);
+                               goto exit;
                        }
                }
        }
@@ -764,14 +750,9 @@ found:
                } else if (EXPECTED(property_offset != ZEND_WRONG_PROPERTY_OFFSET)) {
                        goto write_std_property;
                } else {
-                       if (Z_STRVAL_P(member)[0] == '\0') {
-                               if (Z_STRLEN_P(member) == 0) {
-                                       zend_throw_error(NULL, "Cannot access empty property");
-                                       goto exit;
-                               } else {
-                                       zend_throw_error(NULL, "Cannot access property started with '\\0'");
-                                       goto exit;
-                               }
+                       if (Z_STRVAL_P(member)[0] == '\0' && Z_STRLEN_P(member) != 0) {
+                               zend_throw_error(NULL, "Cannot access property started with '\\0'");
+                               goto exit;
                        }
                }
        } else if (EXPECTED(property_offset != ZEND_WRONG_PROPERTY_OFFSET)) {
@@ -1030,14 +1011,9 @@ static void zend_std_unset_property(zval *object, zval *member, void **cache_slo
                        (*guard) &= ~IN_UNSET;
                        zval_ptr_dtor(&tmp_object);
                } else {
-                       if (Z_STRVAL_P(member)[0] == '\0') {
-                               if (Z_STRLEN_P(member) == 0) {
-                                       zend_throw_error(NULL, "Cannot access empty property");
-                                       goto exit;
-                               } else {
-                                       zend_throw_error(NULL, "Cannot access property started with '\\0'");
-                                       goto exit;
-                               }
+                       if (Z_STRVAL_P(member)[0] == '\0' && Z_STRLEN_P(member) != 0) {
+                               zend_throw_error(NULL, "Cannot access property started with '\\0'");
+                               goto exit;
                        }
                }
        }