From: Nikita Popov Date: Wed, 23 Mar 2016 17:57:59 +0000 (+0100) Subject: Allow empty property names X-Git-Tag: php-7.1.0alpha1~95 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=674297c7e41013c2c34d770051714518d0586271;p=php Allow empty property names Conflicts: Zend/zend_compile.c --- diff --git a/Zend/tests/bug29015.phpt b/Zend/tests/bug29015.phpt index a36ed923f3..d4231d10b1 100644 --- a/Zend/tests/bug29015.phpt +++ b/Zend/tests/bug29015.phpt @@ -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 diff --git a/Zend/tests/bug52484.phpt b/Zend/tests/bug52484.phpt index 053529614d..1d2c2d7cdc 100644 --- a/Zend/tests/bug52484.phpt +++ b/Zend/tests/bug52484.phpt @@ -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 diff --git a/Zend/tests/bug52484_2.phpt b/Zend/tests/bug52484_2.phpt index 6bb927535c..3b12950c66 100644 --- a/Zend/tests/bug52484_2.phpt +++ b/Zend/tests/bug52484_2.phpt @@ -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 diff --git a/Zend/tests/bug52484_3.phpt b/Zend/tests/bug52484_3.phpt index af32bc9be7..408dd453fd 100644 --- a/Zend/tests/bug52484_3.phpt +++ b/Zend/tests/bug52484_3.phpt @@ -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 diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 6aa5d731c5..d95f5d9a33 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -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; } } }