Req #70671 [Opn->Dup]: Fatal Error: Cannot use class because the name is already in use in
| From: | cmb@php.net | Date: | Fri, 24 Jun 2016 19:17:17 +0000 |
| Subject: | Req #70671 [Opn->Dup]: Fatal Error: Cannot use class because the name is already in use in | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201835@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70671&edit=1
ID: 70671
Updated by: cmb@php.net
Reported by: david at grudl dot com
Summary: Fatal Error: Cannot use class because the name is
already in use in
-Status: Open
+Status: Duplicate
Type: Feature/Change Request
Package: Class/Object related
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Duplicate of bug #66862.
Previous Comments:
------------------------------------------------------------------------
[2015-10-08 15:26:13] david at grudl dot com
Description:
------------
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:
---------------
foo.php:
<?php
namespace A;
class Foo
{}
?>
------------
bar.php:
<?php
namespace A;
use Something\Foo;
?>
-------------
demo-fatalerror.php
<?php
include 'foo.php';
include 'bar.php';
?>
-------------
demo-ok.php
<?php
include 'bar.php';
include 'foo.php';
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70671&edit=1