php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62031 namespaces not supported - cannot redeclare class
Submitted: 2012-05-14 16:11 UTC Modified: 2017-01-10 07:59 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: me at kevingh dot com Assigned:
Status: Suspended Package: bcompiler (PECL)
PHP Version: Irrelevant OS: Ubuntu 12.04
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-05-14 16:11 UTC] me at kevingh dot com
Description:
------------
The bcompiler extension triggers a fatal error if writing a file that extends 
another class with the same name, but in a different namespace.

Test script:
---------------
Test.php
<?php

    $fh = fopen('test.bc', 'w');

    bcompiler_write_header($fh);
    bcompiler_write_file($fh, 'ArrayObject.php');
    bcompiler_write_footer($fh);

    fclose($fh);

?>

ArrayObject.php
<?php

    namespace Test;

    class ArrayObject extends \ArrayObject
    {
        public function getId ()
        {
            return spl_object_hash($this);
        }
    }

?>

Expected result:
----------------
No output.

Actual result:
--------------
PHP Fatal error:  Cannot redeclare class Test\ArrayObject in 
/home/kherrera/ArrayObject.php on line 11
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/bcompiler-test:0
PHP   2. bcompiler_write_file() /usr/local/bin/bcompiler-test:31

Fatal error: Cannot redeclare class Test\ArrayObject in 
/home/kherrera/ArrayObject.php on line 11

Call Stack:
    0.0002     645088   1. {main}() /usr/local/bin/bcompiler-test:0
    0.0007     668752   2. bcompiler_write_file() /usr/local/bin/bcompiler-
test:31

---

Now why would anything like this happen? My application is using a class in a 
library that it needs to compile.  That library is Symfony's Finder component, 
which extends the SplFileInfo class to add a couple of new methods.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-14 16:12 UTC] me at kevingh dot com
The test script should have read:

<?php

    require 'ArrayObject.php';

    $fh = fopen('test.bc', 'w');

    bcompiler_write_header($fh);
    bcompiler_write_file($fh, 'ArrayObject.php');
    bcompiler_write_footer($fh);

    fclose($fh);

?>
 [2012-05-15 02:54 UTC] alan_k@php.net
-Summary: cannot redeclare class +Summary: namespaces not supported - cannot redeclare class
 [2012-05-15 02:54 UTC] alan_k@php.net
Namespaces are not supported at present, unless someone want's to contribute the 
code...
 [2012-05-15 09:19 UTC] val@php.net
-Status: Open +Status: Feedback
 [2012-05-15 09:19 UTC] val@php.net
Namespaces are supported by bcompiler, at least their basic functionality was tested (testcase a60). 

I see one obvious problem in the test code used to compile ArrayObject.php. In the compilation script you should not include/require the file being compiled. bcompiler_write_file() function uses the same include/require feature to compile file, so it gets included 2nd time, which may cause the error you see. Could you remove require() and check if the compilation and the compiled bytecodes work?
 [2012-05-15 14:11 UTC] me at kevingh dot com
-Status: Feedback +Status: Open
 [2012-05-15 14:11 UTC] me at kevingh dot com
The example is written precisely because I wanted to point that out.  I have an 
application written in PHP to compile other PHP source.  So if the other source 
code just happens to use the same library I do, it will never work?
 [2017-01-10 07:59 UTC] kalle@php.net
-Status: Open +Status: Suspended
 [2017-01-10 07:59 UTC] kalle@php.net
Suspending this report as the extension have not had a release for almost 6 years.  Please revive this if the extension once again shows life
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 06:01:28 2024 UTC