php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43183 "use" of the same class in difference scripts results in a fatal error
Submitted: 2007-11-03 17:57 UTC Modified: 2007-11-14 03:42 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: chagenbu@php.net Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3CVS-2007-11-03 (CVS) OS: n/a (linux 2.6, mac os x 10.4)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
37 + 6 = ?
Subscribe to this entry?

 
 [2007-11-03 17:57 UTC] chagenbu@php.net
Description:
------------
As per discussion on the PHP internals list, the proper way to ensure that when using a short name, the class loaded is always from the current namespace (even if it needs to be autoloaded and has not yet been loaded) is to import that class in every file where it is used.

However, doing so in two separate scripts, OR just importing a class that has already been defined in the namespace, can result in a fatal error claiming an import clash. Because of the nature of namespaces and this bug it requires 2 small scripts to reproduce, not one.

Reproduce code:
---------------
ns_import1.php:
---------------
<?php

namespace Test;

class Helper {}

include dirname(__FILE__) . '/ns_import2.php';


ns_import2.php:
---------------
<?php

namespace Test;
import Test::Helper;

class Other {}

Expected result:
----------------
No error, should be no output.

Actual result:
--------------
$ php ns_import1.php

Fatal error: Import name 'Helper' conflicts with defined class in /tmp/ns_import2.php on line 5

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-12 15:52 UTC] dmitry@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2007-11-14 03:42 UTC] chagenbu@php.net
Works great now - thanks Dmitry.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC