I've been using PHP's namespaces for some time now and I think it is a great addition to my programming. This morning I wondered about something concerning the use
statement. I'm wondering if the order of use
affects the functonality of my PHP code.
The ability to refer to an external fully qualified name with an alias, or importing, is an important feature of namespaces. This is similar to the ability of unix-based filesystems to create symbolic links to a file or to a directory.
AIn PHP, aliasing is accomplished with the use operator.
~ That sucks, nothing about the order of inclusion. Let's ask my friends on SO!
Below, I'll try to give a better example
namespace Fully\Qualified\Namespace;
use Fully\Qualified\Namespace\B;
use Fully\Qualified\Namespace\A;
class C
{
// ...
}
namespace Fully\Qualified\Namespace;
use Fully\Qualified\Namespace\A;
class B extends A
{
// ...
}
namespace Fully\Qualified\Namespace;
class A
{
// ...
}
Now, will it give me trouble that class B
is included before class A
in my use statements?
When alias namespaces no.
When used in the class body for Traits may affect in certain scenarios related with the use of docblock annotations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With