|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Thu Oct 30 22:00:01 2025 UTC | 
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); ?>