Skip to content

Commit 5a076e6

Browse files
committed
Return error_zval form get_property_ptr_ptr on exception
This goes in the reverse direction of 4463acb. 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.
1 parent 4463acb commit 5a076e6

File tree

5 files changed

+8
-17
lines changed

5 files changed

+8
-17
lines changed

Zend/tests/closure_038.phpt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,5 @@ int(24)
5858
Fatal error: Uncaught Error: Cannot access private property B::$x in %s:%d
5959
Stack trace:
6060
#0 %s(%d): Closure->{closure}()
61-
#1 {main}
62-
63-
Next Error: Cannot access private property B::$x in %s:%d
64-
Stack trace:
65-
#0 %s(%d): Closure->{closure}()
6661
#1 {main}
6762
thrown in %s on line %d

Zend/tests/closure_039.phpt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,5 @@ int(24)
5858
Fatal error: Uncaught Error: Cannot access private property B::$x in %s:%d
5959
Stack trace:
6060
#0 %s(%d): Closure->{closure}()
61-
#1 {main}
62-
63-
Next Error: Cannot access private property B::$x in %s:%d
64-
Stack trace:
65-
#0 %s(%d): Closure->{closure}()
6661
#1 {main}
6762
thrown in %s on line %d

Zend/zend_execute.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2822,6 +2822,9 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
28222822
}
28232823
return;
28242824
}
2825+
} else if (UNEXPECTED(Z_ISERROR_P(ptr))) {
2826+
ZVAL_ERROR(result);
2827+
return;
28252828
}
28262829

28272830
ZVAL_INDIRECT(result, ptr);
@@ -2858,7 +2861,7 @@ static zend_always_inline void zend_assign_to_property_reference(zval *container
28582861
variable_ptr = Z_INDIRECT_P(variable_ptr);
28592862
}
28602863

2861-
if (UNEXPECTED(Z_ISERROR_P(variable_ptr) || EG(exception))) {
2864+
if (UNEXPECTED(Z_ISERROR_P(variable_ptr))) {
28622865
variable_ptr = &EG(uninitialized_zval);
28632866
} else if (UNEXPECTED(Z_TYPE(variable) != IS_INDIRECT)) {
28642867
zend_throw_error(NULL, "Cannot assign by reference to overloaded object");

Zend/zend_object_handlers.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zval *object, zval *member, int typ
10241024
zobj = Z_OBJ_P(object);
10251025
name = zval_try_get_tmp_string(member, &tmp_name);
10261026
if (UNEXPECTED(!name)) {
1027-
return NULL;
1027+
return &EG(error_zval);
10281028
}
10291029

10301030
#if DEBUG_OBJECT_HANDLERS
@@ -1072,6 +1072,8 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zval *object, zval *member, int typ
10721072
zend_error(E_NOTICE, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
10731073
}
10741074
}
1075+
} else if (zobj->ce->__get == NULL) {
1076+
retval = &EG(error_zval);
10751077
}
10761078

10771079
zend_tmp_string_release(tmp_name);

tests/classes/static_properties_003_error4.phpt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ try {
1717
==Done==
1818
--EXPECTF--
1919
--> Access non-visible static prop like instance prop:
20-
Error: Cannot access protected property C::$y in %s:9
21-
Stack trace:
22-
#0 {main}
23-
24-
Next Error: Cannot access protected property C::$y in %s:9
20+
Error: Cannot access protected property C::$y in %s:%d
2521
Stack trace:
2622
#0 {main}
2723
==Done==

0 commit comments

Comments
 (0)