Req #70671 [NEW]: Fatal Error: Cannot use class because the name is already in use in
| From: | david at grudl dot com | Date: | Thu, 08 Oct 2015 15:26:14 +0000 |
| Subject: | Req #70671 [NEW]: Fatal Error: Cannot use class because the name is already in use in | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-196482@lists.php.net to get a copy of this message | ||
From: david at grudl dot com
Operating system:
PHP version: Irrelevant
Package: Class/Object related
Bug Type: Feature/Change Request
Bug description:Fatal Error: Cannot use class because the name is already in use in
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 bug report at https://bugs.php.net/bug.php?id=70671&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70671&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70671&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70671&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70671&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70671&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70671&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70671&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70671&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70671&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70671&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70671&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70671&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70671&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70671&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70671&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70671&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70671&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70671&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70671&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70671&r=mysqlcfg