Bug #76936 [Com]: Objects cannot access their private attributes while handling reflection errors
| From: | sjon at hortensius dot net | Date: | Tue, 02 Oct 2018 15:10:24 +0000 |
| Subject: | Bug #76936 [Com]: Objects cannot access their private attributes while handling reflection errors | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217358@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76936&edit=1
ID: 76936
Comment by: sjon at hortensius dot net
Reported by: juanleon dot lahoz at gmail dot com
Summary: Objects cannot access their private attributes while
handling reflection errors
Status: Open
Type: Bug
Package: Reflection related
Operating System: Linux (Ubuntu 18.04)
PHP Version: 7.2.10
Block user comment: N
Private report: N
New Comment:
This can be reproduced with an even smaller testcase as the Exception is not necessary:
https://3v4l.org/9ScMs
Even better, if the error-handler is executed earlier the problem no longer occurs:
https://3v4l.org/HWETd
Previous Comments:
------------------------------------------------------------------------
[2018-09-26 10:47:02] juanleon dot lahoz at gmail dot com
Description:
------------
In PHP 7.2, if a error is triggered while using reflection to inspect an object,
and a error_handler is set as a method of a class, the error handler object
cannot access its own private attributes.
Short (about 60 lines) and example of the code with comments is here https://gist.github.com/juan-leon/0c33d86b1bda88b6281fdcf451dc1192
Example code is working for PHP 7.0, and its output is in the expected results section.
Example code is failing for PHP 7.2, and its output is in the expected results section (notice the
Fatal Error description)
Test script:
---------------
https://gist.github.com/juan-leon/0c33d86b1bda88b6281fdcf451dc1192
Expected result:
----------------
property dummy1 value is 1
Dealing with error Undefined property: Foo::$dummy2, /home/bb1/www/weird_error5.php, 57
Never executed in PHP7.2; there is a fatal error in the line above
property dummy2 value is
This line is not reached in PHP7.2; but it is reached in PHP 7.0
Actual result:
--------------
property dummy1 value is 1
Dealing with error Undefined property: Foo::$dummy2, /home/bb1/www/weird_error5.php, 57
Fatal error: Uncaught Error: Cannot access private property ErrorHandler::$private in
/home/bb1/www/weird_error5.php:38
Stack trace:
#0 /home/bb1/www/weird_error5.php(28): ErrorHandler->handleError(8, 'Undefined
prope...', '/home/bb1/www/w...', 57)
#1 [internal function]: ErrorHandler->{closure}(8, 'Undefined prope...',
'/home/bb1/www/w...', 57, Array)
#2 /home/bb1/www/weird_error5.php(57): ReflectionProperty->getValue(Object(Foo))
#3 /home/bb1/www/weird_error5.php(66): reproduceBug(Object(Foo))
#4 {main}
thrown in /home/bb1/www/weird_error5.php on line 38
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76936&edit=1