Edit report at https://bugs.php.net/bug.php?id=55068&edit=1
ID: 55068 Updated by: dmi...@php.net Reported by: frederic dot hardy at mageekbox dot net Summary: Namespace importation order seems relevant -Status: Open +Status: Bogus Type: Bug Package: Scripting Engine problem Operating System: Ubuntu PHP Version: 5.3.6 Block user comment: N Private report: N New Comment: This is not a bug. It's the expected behaviour. In case a class is already defined you can't "use" another class with the same name. But on the other hand "use" statement has effect only on current PHP file so you can "use" class in some file and declare it later. Previous Comments: ------------------------------------------------------------------------ [2011-06-29 11:42:46] frederic dot hardy at mageekbox dot net Description: ------------ 1) Create the file named main.php (see test script section). 2) In the same directory of main.php, create a file named ns_class2.php (see test script section). 3) In the same directory of main.php, create a file named ns_ns1_ns2_class1.php (see test script section). 4) In the same directory of main.php, create a file named ns_ns1_ns2_class2.php (see test script section). 5) Execute php -n main.php in CLI. 6) Invert require_once 'ns_ns1_ns2_class2.php' and require_once 'ns_ns1_ns2_class1.php' in main.php. 5) Execute php -n main.php in CLI. Test script: --------------- file main.php : <?php require_once 'ns_class2.php'; require_once 'ns_ns1_ns2_class2.php'; require_once 'ns_ns1_ns2_class1.php'; ?> file ns_class2.php : <?php namespace ns; class class2 {} ?> file ns_ns1_ns2_class1.php : <?php namespace ns\ns1\ns2; use ns\class2; class class1 {} ?> file ns_ns1_ns2_class2.ph : <?php namespace ns\ns1\ns2; class class2 {} ?> Expected result: ---------------- Nothing in all cases. Actual result: -------------- When ns_ns1_ns2_class2.php was included before ns_ns1_ns2_class1.php : Fatal error: Cannot use ns\class2 as class2 because the name is already in use in /home/fhardy/tmp/ns_ns1_ns2_class1.php on line 5 When ns_ns1_ns2_class2.php was included after ns_ns1_ns2_class1.php : Nothing ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55068&edit=1