PHP namespace error?
namespaces, php
Solution
After few tests: PHP file with few namespaces behave difficult to understand, try to do not use more then one namespace in one file.
(It's because of linking to not existing classes while parsing [of one file!] that change order of PHP parsing, C++ things [pointers] - I can't explain that.)
As PHP doc says: "It is strongly discouraged as a coding practice to combine multiple namespaces into the same file."
More about tests I did and documentation we studied to find it out:
https://chat.stackoverflow.com/rooms/71776/discussion-between-axiac-and-jack
Problem
PHP 5.6 This code: ``` <?php namespace Database { abstract class Model { } } namespace Models { use Database\Model as DbModel; class Model extends DbModel { } } namespace Models { use Database\Model; class Brand extends Model { } } namespace { $m = new \Models\Model(); } ``` causes an error: "Fatal error: Cannot use Database\Model as Model because the name is already in use in D:\OpenServer\domains\localhost\index.php on line 23". This code: ``` <?php namespace Models { use Database\Model as DbModel; class Model extends DbModel { } } namespace Models { use Database\Model; class Brand extends Model { } } namespace Database { abstract class Model { } } namespace { $m = new \Models\Model(); } ``` has no errors. Why is this happening? Because the code has not been changed.