php.net |  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
Votes:2
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
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: nicolas dot grekas+php at gmail dot com
New email:
PHP Version: OS:

 

 [2012-01-12 10:25 UTC] nicolas dot grekas+php at gmail dot com
Description:
------------
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:
https://bugs.php.net/bug.php?id=42098

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:
---------------
<?php

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

error_reporting(E_ALL | E_STRICT);

set_error_handler('eh');

// 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(';');
    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

Patches

patch-01 (last revision 2014-02-05 15:46 UTC by jpauli@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

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] jpauli@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: jpauli
 [2014-02-05 14:29 UTC] jpauli@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

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] jpauli@php.net
The following patch has been added/updated:

Patch Name: patch-01
Revision:   1391615195
URL:        https://bugs.php.net/patch-display.php?bug=60724&patch=patch-01&revision=1391615195
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC