]> granicus.if.org Git - php/commitdiff
Fix bug #68188
authorNikita Popov <nikic@php.net>
Fri, 3 Oct 2014 19:24:28 +0000 (21:24 +0200)
committerNikita Popov <nikic@php.net>
Fri, 3 Oct 2014 19:26:39 +0000 (21:26 +0200)
NEWS
Zend/tests/bug68118.phpt [new file with mode: 0644]
Zend/zend_object_handlers.c

diff --git a/NEWS b/NEWS
index d4f6c3e9fb8652f7c64b90e345791744c6f0487a..00bc11062269076f0b617cc0ab016a2d1de9d993 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2014, PHP 5.5.19
 
+- Core:
+  . Fixed bug #68188 ($a->foo .= 'test'; can leave $a->foo undefined). (Nikita)
+
 
 ?? ??? 2014, PHP 5.5.18
 
diff --git a/Zend/tests/bug68118.phpt b/Zend/tests/bug68118.phpt
new file mode 100644 (file)
index 0000000..c56e70a
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Bug #68118: $a->foo .= 'test'; can leave $a->foo undefined
+--FILE--
+<?php
+
+set_error_handler(function() {
+    $obj = new stdClass;
+    $obj->test = 'meow';
+    return true;
+});
+$a = new stdClass;
+$a->undefined .= 'test';
+var_dump($a);
+
+?>
+--EXPECT--
+object(stdClass)#2 (1) {
+  ["undefined"]=>
+  string(4) "test"
+}
index 093951eecafc6fe183131f8d6057e1e88e690f47..a7b761fa3841962ed4d5531d7516e517cef48b5c 100644 (file)
@@ -754,9 +754,6 @@ static zval **zend_std_get_property_ptr_ptr(zval *object, zval *member, int type
                        /* we don't have access controls - will just add it */
                        new_zval = &EG(uninitialized_zval);
 
-                       if(UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) {
-                               zend_error(E_NOTICE, "Undefined property: %s::$%s", zobj->ce->name, Z_STRVAL_P(member));
-                       }
                        Z_ADDREF_P(new_zval);
                        if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
                            property_info->offset >= 0) {
@@ -776,6 +773,12 @@ static zval **zend_std_get_property_ptr_ptr(zval *object, zval *member, int type
                                }
                                zend_hash_quick_update(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, &new_zval, sizeof(zval *), (void **) &retval);
                        }
+
+                       /* Notice is thrown after creation of the property, to avoid EG(std_property_info)
+                        * being overwritten in an error handler. */
+                       if (UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) {
+                               zend_error(E_NOTICE, "Undefined property: %s::$%s", zobj->ce->name, Z_STRVAL_P(member));
+                       }
                } else {
                        /* we do have getter - fail and let it try again with usual get/set */
                        retval = NULL;