Bug #65014 [Opn->Ana]: namespaced class not found after including it in an error handler
Edit report at https://bugs.php.net/bug.php?id=65014&edit=1
ID: 65014
Updated by: cmb@php.net
Reported by: alexander dot stehlik at gmail dot com
Summary: namespaced class not found after including it in an
error handler
-Status: Open
+Status: Analyzed
Type: Bug
Package: Unknown/Other Function
-Operating System: Ubuntu 12.10 / CentOS 6.4
+Operating System: *
-PHP Version: 5.4.16
+PHP Version: 5.6.11
Block user comment: N
Private report: N
New Comment:
When a file is compiled all relevant info of the use statements
are stored in the compiler globals CG(current_import*). When the
compilation of the file is finished, these globals are freed.
In the given case the use statement in deprecated_reference.php
sets an entry in CG(current_import). Due to the deprecated notice
during compile time and the error handler, another file
(namespaced_class.php) is included and compiled, so
CG(current_import) is reset, and after the file has been compiled,
freed. Then compilation of deprecated_reference.php continues with
the unitialized CG(current_import) -- effectively, the use
statement is forgotten, and so the same error is raised as if the
use statement was missing in the first place.
Basically, I see two ways to fix this issue: either avoid nested
compilation, or cater to it by making the respective compiler
globals stacks.
Previous Comments:
------------------------------------------------------------------------
[2013-06-11 15:50:22] alexander dot stehlik at gmail dot com
Description:
------------
This bug was pretty hard to track down. I uploaded a test script to make it
clear.
These conditions need to be met to trigger the bug:
1. You use a custom error handler
2. You use namespaces
3. You use the "use" statement
4. You require a class within the error handler
5. You have a class that uses a deprecated = & new Classname() statment
Using an autoloader is no workaround because the system thinks the namespaced
class is available (class_exists() returns true).
Test script:
---------------
To reproduce the bug several files are needed. I uploaded a test script. You can download it here:
https://docs.google.com/file/d/0Bz4hXLAjQnaiRlJWblNuX1psdzg/edit?usp=sharing
No Google account required for download!
Please call index.php and you will see an error:
Fatal error: Class 'namespaced_class' not found in requireerror/deprecated_reference.php
on line 42
Please have a look at the code to see how it occurs.
Expected result:
----------------
I expect the class that is found by class_exists() and included with a "use"
statement is accessible.
Actual result:
--------------
I get an error:
Fatal error: Class 'namespaced_class' not found in deprecated_reference.php on
line 31
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65014&edit=1
Thread (2 messages)