summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2018-10-02 17:47:07 +0200
committerNikita Popov <nikita.ppv@gmail.com>2018-10-02 17:47:07 +0200
commitd2477b284b73adb12fb9694d144855a468fe8825 (patch)
tree786e2c4295d7c8415ad94e4cc9f1c1fad3f71efa
parent56d157851515178f8e27bd90b1ef4925d671fda6 (diff)
downloadphp-git-d2477b284b73adb12fb9694d144855a468fe8825.tar.gz
Fixed bug #76936
-rw-r--r--NEWS4
-rw-r--r--Zend/zend.c6
-rw-r--r--ext/reflection/tests/bug76936.phpt45
3 files changed, 55 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index eb845cbe69..7a6e0ea69d 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 72a7b4d588..6ee1a017b8 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 0000000000..4f8226e53c
--- /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 =