|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70671 Fatal Error: Cannot use class because the name is already in use in
Submitted: 2015-10-08 15:26 UTC Modified: 2016-06-24 19:17 UTC
Avg. Score:4.6 ± 0.5
Reproduced:6 of 6 (100.0%)
Same Version:6 (100.0%)
Same OS:3 (50.0%)
From: david at grudl dot com Assigned: cmb (profile)
Status: Duplicate Package: Class/Object related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: david at grudl dot com
New email:
PHP Version: OS:


 [2015-10-08 15:26 UTC] david at grudl dot com
PHP produces unnecessary "Fatal error: Cannot use Something\Foo as Foo because the name is already in use in bar.php". There is no reason to throw such error.

The error is insidious because it dependents on the order in which the files are loaded, which is (with autoloading) unpredictable. In reverse order (see demo-ok.php) is everything ok.

Moreover, in PHP 7 it is not possible to catch this error via try ... catch or even via set_exception_handler(). 

Test script:

namespace A;

class Foo 


namespace A;

use Something\Foo;


include 'foo.php';
include 'bar.php';


include 'bar.php';
include 'foo.php';


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-24 19:17 UTC]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2016-06-24 19:17 UTC]
Duplicate of bug #66862.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Apr 04 06:01:23 2020 UTC