xref: /PHP-8.0/ext/reflection/tests/bug76936.phpt (revision d2477b28)
1--TEST--
2Bug #76936: Objects cannot access their private attributes while handling reflection errors
3--FILE--
4<?php
5
6class Foo {
7    public $dummy1;
8    public $dummy2;
9}
10
11class 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;
34unset($f->dummy2);
35
36foreach ((new ReflectionObject($f))->getProperties() as $p) {
37    echo $p->getName() .' = '. $p->getValue($f) ."\n";
38}
39
40?>
41--EXPECT--
42dummy1 =
43ErrorHandler::handleError dealing with error Undefined property: Foo::$dummy2
44THIS IS PRIVATE
45dummy2 =
46