|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-06-24 19:17 UTC] cmb@php.net
-Status: Open
+Status: Duplicate
-Assigned To:
+Assigned To: cmb
[2016-06-24 19:17 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 17:00:01 2025 UTC |
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'; ?>