com php-src: Fixed bug #76936: NEWS Zend/zend.c ext/reflection/tests/bug76936.phpt
| From: | Nikita Popov | Date: | Tue, 02 Oct 2018 15:47:07 +0000 |
| Subject: | com php-src: Fixed bug #76936: NEWS Zend/zend.c ext/reflection/tests/bug76936.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-103304@lists.php.net to get a copy of this message | ||
Commit: d2477b284b73adb12fb9694d144855a468fe8825
Author: Nikita Popov <nikita.ppv@gmail.com> Tue, 2 Oct 2018 17:47:07 +0200
Parents: 56d157851515178f8e27bd90b1ef4925d671fda6
Branches: PHP-7.2 PHP-7.3 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d2477b284b73adb12fb9694d144855a468fe8825
Log:
Fixed bug #76936
Bugs:
https://bugs.php.net/76936
Changed paths:
M NEWS
M Zend/zend.c
A ext/reflection/tests/bug76936.phpt
Diff:
diff --git a/NEWS b/NEWS
index eb845cb..7a6e0ea 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,10 @@ PHP NEWS
(Nikita)
. Fixed bug #76946 (Cyclic reference in generator not detected). (Nikita)
+- Reflection:
+ .. Fixed bug #76936 (Objects cannot access their private attributes while
+ handling reflection errors). (Nikita)
+
11 Oct 2018, PHP 7.2.11
- Core:
diff --git a/Zend/zend.c b/Zend/zend.c
index 72a7b4d..6ee1a01 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -1117,6 +1117,7 @@ static ZEND_COLD void zend_error_va_list(int type, const char *format, va_list
a
zend_stack loop_var_stack;
zend_stack delayed_oplines_stack;
zend_array *symbol_table;
+ zend_class_entry *orig_fake_scope;
/* Report about uncaught exception in case of fatal errors */
if (EG(exception)) {
@@ -1271,6 +1272,9 @@ static ZEND_COLD void zend_error_va_list(int type, const char *format, va_list
a
CG(in_compilation) = 0;
}
+ orig_fake_scope = EG(fake_scope);
+ EG(fake_scope) = NULL;
+
if (call_user_function_ex(CG(function_table), NULL, &orig_user_error_handler, &retval,
5, params, 1, NULL) == SUCCESS) {
if (Z_TYPE(retval) != IS_UNDEF) {
if (Z_TYPE(retval) == IS_FALSE) {
@@ -1283,6 +1287,8 @@ static ZEND_COLD void zend_error_va_list(int type, const char *format, va_list
a
zend_error_cb(type, error_filename, error_lineno, format, args);
}
+ EG(fake_scope) = orig_fake_scope;
+
if (in_compilation) {
CG(active_class_entry) = saved_class_entry;
RESTORE_STACK(loop_var_stack);
diff --git a/ext/reflection/tests/bug76936.phpt b/ext/reflection/tests/bug76936.phpt
new file mode 100644
index 0000000..4f8226e
--- /dev/null
+++ b/ext/reflection/tests/bug76936.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Bug #76936: Objects cannot access their private attributes while handling reflection errors
+--FILE--
+<?php
+
+class Foo {
+ public $dummy1;
+ public $dummy2;
+}
+
+class ErrorHandler {
+ private $private = 'THIS IS PRIVATE'."\n";
+
+ function __construct() {
+ set_error_handler(
+ function ($errno, $errstr, $errfile, $errline) {
+ $this->handleError($errno, $errstr, $errfile, $errline);
+ }
+ );
+ }
+
+ private function handleError($errno, $errstr, $errfile, $errline, $errmodule = null) {
+ echo __METHOD__. " dealing with error $errstr\n";
+
+ // This attribute is no longer accessible in this object. Same for other
+ // objects and their private attributes once we reach in this state.
+ echo $this->private;
+ }
+}
+
+$errorHandler = new ErrorHandler();
+
+$f = new Foo;
+unset($f->dummy2);
+
+foreach ((new ReflectionObject($f))->getProperties() as $p) {
+ echo $p->getName() .' = '. $p->getValue($f) ."\n";
+}
+
+?>
+--EXPECT--
+dummy1 =
+ErrorHandler::handleError dealing with error Undefined property: Foo::$dummy2
+THIS IS PRIVATE
+dummy2 =