Skip to content

Commit d2477b2

Browse files
committed
Fixed bug #76936
1 parent 56d1578 commit d2477b2

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ PHP NEWS
77
(Nikita)
88
. Fixed bug #76946 (Cyclic reference in generator not detected). (Nikita)
99

10+
- Reflection:
11+
. Fixed bug #76936 (Objects cannot access their private attributes while
12+
handling reflection errors). (Nikita)
13+
1014
11 Oct 2018, PHP 7.2.11
1115

1216
- Core:

Zend/zend.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ static ZEND_COLD void zend_error_va_list(int type, const char *format, va_list a
11171117
zend_stack loop_var_stack;
11181118
zend_stack delayed_oplines_stack;
11191119
zend_array *symbol_table;
1120+
zend_class_entry *orig_fake_scope;
11201121

11211122
/* Report about uncaught exception in case of fatal errors */
11221123
if (EG(exception)) {
@@ -1271,6 +1272,9 @@ static ZEND_COLD void zend_error_va_list(int type, const char *format, va_list a
12711272
CG(in_compilation) = 0;
12721273
}
12731274

1275+
orig_fake_scope = EG(fake_scope);
1276+
EG(fake_scope) = NULL;
1277+
12741278
if (call_user_function_ex(CG(function_table), NULL, &orig_user_error_handler, &retval, 5, params, 1, NULL) == SUCCESS) {
12751279
if (Z_TYPE(retval) != IS_UNDEF) {
12761280
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
12831287
zend_error_cb(type, error_filename, error_lineno, format, args);
12841288
}
12851289

1290+
EG(fake_scope) = orig_fake_scope;
1291+
12861292
if (in_compilation) {
12871293
CG(active_class_entry) = saved_class_entry;
12881294
RESTORE_STACK(loop_var_stack);

ext/reflection/tests/bug76936.phpt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
Bug #76936: Objects cannot access their private attributes while handling reflection errors
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public $dummy1;
8+
public $dummy2;
9+
}
10+
11+
class ErrorHandler {
12+
private $private = 'THIS IS PRIVATE'."\n";
13+
14+
function __construct() {
15+
set_error_handler(
16+
function ($errno, $errstr, $errfile, $errline) {
17+
$this->handleError($errno, $errstr, $errfile, $errline);
18+
}
19+
);
20+
}
21+
22+
private function handleError($errno, $errstr, $errfile, $errline, $errmodule = null) {
23+
echo __METHOD__. " dealing with error $errstr\n";
24+
25+
// This attribute is no longer accessible in this object. Same for other
26+
// objects and their private attributes once we reach in this state.
27+
echo $this->private;
28+
}
29+
}
30+
31+
$errorHandler = new ErrorHandler();
32+
33+
$f = new Foo;
34+
unset($f->dummy2);
35+
36+
foreach ((new ReflectionObject($f))->getProperties() as $p) {
37+
echo $p->getName() .' = '. $p->getValue($f) ."\n";
38+
}
39+
40+
?>
41+
--EXPECT--
42+
dummy1 =
43+
ErrorHandler::handleError dealing with error Undefined property: Foo::$dummy2
44+
THIS IS PRIVATE
45+
dummy2 =

0 commit comments

Comments
 (0)