php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65014 namespaced class not found after including it in an error handler
Submitted: 2013-06-11 15:50 UTC Modified: 2020-12-07 16:46 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: alexander dot stehlik at gmail dot com Assigned:
Status: Analyzed Package: Scripting Engine problem
PHP Version: 5.6.11 OS: *
Private report: No CVE-ID: None
 [2013-06-11 15:50 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-16 22:03 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Operating System: Ubuntu 12.10 / CentOS 6.4 +Operating System: * -PHP Version: 5.4.16 +PHP Version: 5.6.11
 [2015-07-16 22:03 UTC] cmb@php.net
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.
 [2020-12-07 16:46 UTC] cmb@php.net
-Package: Unknown/Other Function +Package: Scripting Engine problem
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 06:01:30 2024 UTC