com php-src: Explicitly check for exceptions in by-ref obj prop assign: Zend/zend_execute.c tests/classes/static_properties_ 003_error4.phpt
| From: | Nikita Popov | Date: | Thu, 10 Oct 2019 12:41:35 +0000 |
| Subject: | com php-src: Explicitly check for exceptions in by-ref obj prop assign: Zend/zend_execute.c tests/classes/static_properties_ 003_error4.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-108862@lists.php.net to get a copy of this message | ||
Commit: 4463acb9513dfb62206760c49b3da1fe4d92f40a
Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 10 Oct 2019 14:41:35 +0200
Parents: 12f4e9e020c3968c5a201ef96c4ee589ad36e5e5
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=4463acb9513dfb62206760c49b3da1fe4d92f40a
Log:
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.
Changed paths:
M Zend/zend_execute.c
M tests/classes/static_properties_003_error4.phpt
Diff:
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index b69d0a88d55..368d6b2dcc8 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -2858,7 +2858,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))) {
+ if (UNEXPECTED(Z_ISERROR_P(variable_ptr) || EG(exception))) {
variable_ptr = &EG(uninitialized_zval);
} else if (UNEXPECTED(Z_TYPE(variable) != IS_INDIRECT)) {
zend_throw_error(NULL, "Cannot assign by reference to overloaded object");
diff --git a/tests/classes/static_properties_003_error4.phpt
b/tests/classes/static_properties_003_error4.phpt
index 6a4eafcd2a8..7c54fc42adb 100644
--- a/tests/classes/static_properties_003_error4.phpt
+++ b/tests/classes/static_properties_003_error4.phpt
@@ -8,17 +8,20 @@ class C {
$c = new C;
echo "\n--> Access non-visible static prop like instance prop:\n";
-$c->y =& $ref;
+try {
+ $c->y =& $ref;
+} catch (Error $e) {
+ echo $e, "\n";
+}
?>
==Done==
--EXPECTF--
--> Access non-visible static prop like instance prop:
-
-Fatal error: Uncaught Error: Cannot access protected property C::$y in %s:8
+Error: Cannot access protected property C::$y in %s:9
Stack trace:
#0 {main}
-Next Error: Cannot access protected property C::$y in %s:8
+Next Error: Cannot access protected property C::$y in %s:9
Stack trace:
#0 {main}
- thrown in %s on line 8
+==Done==