Bug #66862 [NEW]: (Sub-)Namespaces unexpected behaviour

From: Date: Sun, 09 Mar 2014 13:57:09 +0000
Subject: Bug #66862 [NEW]: (Sub-)Namespaces unexpected behaviour
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184636@lists.php.net to get a copy of this message
From: celestino dot diaz at gmx dot de Operating system: LINUX PHP version: Irrelevant Package: Scripting Engine problem Bug Type: Bug Bug description:(Sub-)Namespaces unexpected behaviour Description: ------------ PHP v5.5.10 Namespaces have an unexpected behaviour depending on the script loading order. Directory Structure: Sample |_ classA.php |_ classB.php |_ Subnamespace |_ classA.php Test 1: Output: Fatal error: Cannot use Sample\Subnamespace\classA as classA because the name is already in use in Sample/classB.php on line 3 Test 2 (changed script oder): Output: Sample\classB Sample\Subnamespace\classA Sample\classA Sample\classB Sample\Subnamespace\classA Test script: --------------- Sample\classA.php: <?php namespace Sample; class classA {} Sample\classB.php: <?php namespace Sample; use Sample\Subnamespace\classA; class classB { public $classA; public function __construct() { $this->classA = new classA(); } } Sample\Subnamespace\classA.php: <?php namespace Sample; class classA {} Test 1: $a = new Sample\classA(); echo get_class($a)."\n"; $b = new Sample\classB(); echo get_class($b)."\n"; echo get_class($b->classA)."\n"; Test 2: $b = new Sample\classB(); echo get_class($b)."\n"; echo get_class($b->classA)."\n"; $a = new Sample\classA(); echo get_class($a)."\n"; $b = new Sample\classB(); echo get_class($b)."\n"; Expected result: ---------------- Both (Test 1 & 2) should have the same output. -- Edit bug report at https://bugs.php.net/bug.php?id=66862&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66862&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66862&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66862&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66862&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66862&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66862&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66862&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66862&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66862&r=support Expected behavior: https://bugs.php.net/fix.php?id=66862&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66862&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66862&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66862&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66862&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66862&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66862&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66862&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66862&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66862&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66862&r=mysqlcfg

« previous php.bugs (#184636) next »