Bugs php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login

go to bug id or search bugs for

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-2025 The PHP Group
All rights reserved. Last updated: Fri Oct 17 22:00:01 2025 UTC

AltStyle によって変換されたページ (->オリジナル) /