Skip to content

Commit 4463acb

Browse files
committed
Explicitly check for exceptions in by-ref obj prop assign
Relying on setting ERROR if an exception happened during the property address fetch is both a bit fragile and may pessimize other codepaths that will check for exceptions in the VM. Adding an extra exception check instead, which should also allow us to drop the use of ERROR in this area in master.
1 parent 12f4e9e commit 4463acb

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Zend/zend_execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2858,7 +2858,7 @@ static zend_always_inline void zend_assign_to_property_reference(zval *container
28582858
variable_ptr = Z_INDIRECT_P(variable_ptr);
28592859
}
28602860

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

tests/classes/static_properties_003_error4.phpt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ class C {
88
$c = new C;
99

1010
echo "\n--> Access non-visible static prop like instance prop:\n";
11-
$c->y =& $ref;
11+
try {
12+
$c->y =& $ref;
13+
} catch (Error $e) {
14+
echo $e, "\n";
15+
}
1216
?>
1317
==Done==
1418
--EXPECTF--
1519
--> Access non-visible static prop like instance prop:
16-
17-
Fatal error: Uncaught Error: Cannot access protected property C::$y in %s:8
20+
Error: Cannot access protected property C::$y in %s:9
1821
Stack trace:
1922
#0 {main}
2023

21-
Next Error: Cannot access protected property C::$y in %s:8
24+
Next Error: Cannot access protected property C::$y in %s:9
2225
Stack trace:
2326
#0 {main}
24-
thrown in %s on line 8
27+
==Done==

0 commit comments

Comments
 (0)