php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76936 Objects cannot access their private attributes while handling reflection errors
Submitted: 2018-09-26 10:47 UTC Modified: 2018-10-02 15:41 UTC
From: juanleon dot lahoz at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: 7.2.10 OS: Linux (Ubuntu 18.04)
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: juanleon dot lahoz at gmail dot com
New email:
PHP Version: OS:

 

 [2018-09-26 10:47 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-02 15:10 UTC] 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-10-02 15:41 UTC] nikic@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: nikic
 [2018-10-02 15:49 UTC] nikic@php.net
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
 [2018-10-02 15:49 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC