]> granicus.if.org Git - php/commitdiff
Return error_zval form get_property_ptr_ptr on exception
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 10 Oct 2019 13:14:04 +0000 (15:14 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 10 Oct 2019 13:14:04 +0000 (15:14 +0200)
This goes in the reverse direction of 4463acb9513dfb62206760c49b3da1fe4d92f40a.
After looking around a bit, it seems that we already check for
Z_ISERROR_P() on the get_property_ptr_ptr return value in other places.
So do this in zend_fetch_property_address() as well, and also make
sure that EG(error_zval) is indeed returned on exception in
get_property_ptr_ptr.

In particular, this fixes the duplicate exceptions that we used to
get because first get_property_ptr_ptr threw one and then
read_property throws the same exception again.

Zend/tests/closure_038.phpt
Zend/tests/closure_039.phpt
Zend/zend_execute.c
Zend/zend_object_handlers.c
tests/classes/static_properties_003_error4.phpt

index 568db49b81b87f3cb76f18248ffa891959839676..d1ec446c9d2ec39e48e575b07dea88da50c233d7 100644 (file)
@@ -58,10 +58,5 @@ int(24)
 Fatal error: Uncaught Error: Cannot access private property B::$x in %s:%d
 Stack trace:
 #0 %s(%d): Closure->{closure}()
-#1 {main}
-
-Next Error: Cannot access private property B::$x in %s:%d
-Stack trace:
-#0 %s(%d): Closure->{closure}()
 #1 {main}
   thrown in %s on line %d
index f72223d206d5d95a6992d6f4207c592e2703e24b..fa454c38c4d7f2b268ebcbaf068aec5d1fd20021 100644 (file)
@@ -58,10 +58,5 @@ int(24)
 Fatal error: Uncaught Error: Cannot access private property B::$x in %s:%d
 Stack trace:
 #0 %s(%d): Closure->{closure}()
-#1 {main}
-
-Next Error: Cannot access private property B::$x in %s:%d
-Stack trace:
-#0 %s(%d): Closure->{closure}()
 #1 {main}
   thrown in %s on line %d
index 368d6b2dcc8ba2150609b432f7709c2a3bdd0014..04aa3fee6e63cf380a0f5c2f58ffdbdc7865a1ad 100644 (file)
@@ -2822,6 +2822,9 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
                        }
                        return;
                }
+       } else if (UNEXPECTED(Z_ISERROR_P(ptr))) {
+               ZVAL_ERROR(result);
+               return;
        }
 
        ZVAL_INDIRECT(result, ptr);
@@ -2858,7 +2861,7 @@ static zend_always_inline void zend_assign_to_property_reference(zval *container
                variable_ptr = Z_INDIRECT_P(variable_ptr);
        }
 
-       if (UNEXPECTED(Z_ISERROR_P(variable_ptr) || EG(exception))) {
+       if (UNEXPECTED(Z_ISERROR_P(variable_ptr))) {
                variable_ptr = &EG(uninitialized_zval);
        } else if (UNEXPECTED(Z_TYPE(variable) != IS_INDIRECT)) {
                zend_throw_error(NULL, "Cannot assign by reference to overloaded object");
index 65aefb6aec6c06de8625616ec2aa9bd786f01a3c..09984390c90246c6209f15bb2e8781602f155dfd 100644 (file)
@@ -1024,7 +1024,7 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zval *object, zval *member, int typ
        zobj = Z_OBJ_P(object);
        name = zval_try_get_tmp_string(member, &tmp_name);
        if (UNEXPECTED(!name)) {
-               return NULL;
+               return &EG(error_zval);
        }
 
 #if DEBUG_OBJECT_HANDLERS
@@ -1072,6 +1072,8 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zval *object, zval *member, int typ
                                zend_error(E_NOTICE, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
                        }
                }
+       } else if (zobj->ce->__get == NULL) {
+               retval = &EG(error_zval);
        }
 
        zend_tmp_string_release(tmp_name);
index 7c54fc42adb6544522646a981a3e7e23aa3f1d2d..a96ffb29779e3ac9bfbc39a721376c63c1fc94f9 100644 (file)
@@ -17,11 +17,7 @@ try {
 ==Done==
 --EXPECTF--
 --> Access non-visible static prop like instance prop:
-Error: Cannot access protected property C::$y in %s:9
-Stack trace:
-#0 {main}
-
-Next Error: Cannot access protected property C::$y in %s:9
+Error: Cannot access protected property C::$y in %s:%d
 Stack trace:
 #0 {main}
 ==Done==