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: 2015-07-16 22:03 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: Unknown/Other Function
PHP Version: 5.6.11 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alexander dot stehlik at gmail dot com
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat May 25 21:01:27 2019 UTC