Bug #76936 [Asn->Csd]: Objects cannot access their private attributes while handling reflection errors

From: Date: Tue, 02 Oct 2018 15:49:18 +0000
Subject: Bug #76936 [Asn->Csd]: Objects cannot access their private attributes while handling reflection errors
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217363@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 Updated by: nikic@php.net Reported by: juanleon dot lahoz at gmail dot com Summary: Objects cannot access their private attributes while handling reflection errors -Status: Assigned +Status: Closed Type: Bug Package: Reflection related Operating System: Linux (Ubuntu 18.04) PHP Version: 7.2.10 Assigned To: nikic Block user comment: N Private report: N New Comment: Automatic comment on behalf of nikita.ppv@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=d2477b284b73adb12fb9694d144855a468fe8825 Log: Fixed bug #76936 Previous Comments: ------------------------------------------------------------------------ [2018-10-02 15:10:24] sjon at hortensius dot net 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 ------------------------------------------------------------------------ [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

« previous php.bugs (#217363) next »