Does use statement order affect functionality in PHP?

那年仲夏 提交于 2020-01-03 13:33:18

问题


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.

According to PHP.net

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!

Example

Below, I'll try to give a better example

Class C

namespace Fully\Qualified\Namespace;

use Fully\Qualified\Namespace\B;
use Fully\Qualified\Namespace\A;

class C
{
    // ...
}

Class B

namespace Fully\Qualified\Namespace;

use Fully\Qualified\Namespace\A;

class B extends A
{
    // ...
}

Class 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?


回答1:


When alias namespaces no.

When used in the class body for Traits may affect in certain scenarios related with the use of docblock annotations.



来源:https://stackoverflow.com/questions/33341955/does-use-statement-order-affect-functionality-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!