|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60724 Includes fails at compile time when using bracketed namespaces
Submitted: 2012-01-12 10:25 UTC Modified: 2014-02-05 14:29 UTC
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: nicolas dot grekas+php at gmail dot com Assigned: jpauli (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.4 OS:
Private report: No CVE-ID: None
 [2012-01-12 10:25 UTC] nicolas dot grekas+php at gmail dot com
Tested in 5.3.8, 5.2.9 and 5.4RC5, APC not enabled.

At compile time, two nested includes fail when both use bracketed namespaces or mix bracketed and unbracketed ones.

The compile time behavior of PHP is described in:

I found a workaround that makes me think that some internal state is not initialized correctly when using namespaces.

See test script for more details.

Test script:

// This test script uses eval, but the same arise when including files.

error_reporting(E_ALL | E_STRICT);


// The code in the eval triggers an E_DEPRECATED because of "=& new"
// so eh() is called to handle the error, _at_compile_time_.
// Note the unbracketed namespace declaration.
eval('namespace b; $a =& new \stdClass; ');

function eh()
    // dynamically load class a\abc,
    // using bracketed namespace declaration
    // but this fails with fatal error.
    // uncomment the following line, and things work again perfectly.
    eval('namespace a{ class abc{} }');
    print_r(new a\abc);

Expected result:
No error

Actual result:
Fatal error: Cannot mix bracketed namespace declarations with unbracketed namespace declarations


patch-01 (last revision 2014-02-05 15:46 UTC by

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-07 11:37 UTC] nicolas dot grekas+php at gmail dot com
-PHP Version: 5.4.0RC5 +PHP Version: 5.4.4
 [2012-08-07 11:37 UTC] nicolas dot grekas+php at gmail dot com
The bug is still there is the latest version of PHP
 [2014-02-05 14:29 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: jpauli
 [2014-02-05 14:29 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is exepected behavior.

E_STRICT often happens when the engine is in compilation phase.
The compiler is not re-entrant, then when the error is triggered, the second eval() is run, which itself triggers compilation while the preceding compilation phase is not cleared yet.

The second eval() then suffers from the compilation context of the first one.
We can't change that. We, however, could add an error in the eval() OPCode to check for unclean previous compiler state.
 [2014-02-05 15:46 UTC]
The following patch has been added/updated:

Patch Name: patch-01
Revision:   1391615195
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Jul 31 13:01:25 2021 UTC