Alias overview PHP5.3 + supports namespace. An important feature of a namespace is that you can use an alias (alias) to reference a name that complies with the rules. Namespace supports alias reference (or introduced) in the form of 3: class alias, interface alias, and namespace alias. PHP
Alias overview PHP5.3 + supports namespace. An important feature of a namespace is that you can use an alias (alias) to reference a name that complies with the rules. Namespace supports alias reference (or introduced) in the form of 3: class alias, interface alias, and namespace alias. PHP
Alias Overview
PHP5.3 + supports namespace. An important feature of a namespace is that you can use an alias (alias) to reference a name that complies with the rules.
Namespace supports alias reference (or introduced) in the form of 3: class alias, interface alias, and namespace alias.
PHP5.6 + also supports function alias and constant alias.
(Note: the Chinese description of the alias section on the php.net website is ambiguous and incorrect. Correct the preceding description)
Syntax format
Use xxx \ xxx as xx;
Therefore, the use statement is actually an alias reference, rather than a common import Statement. The name after use must be an alias that complies with the rules.
Errors and causes
Now let's take a look at the error message in a similar article title:
"The use statement with non-compound name... Has no effect"
We can understand that this error message indicates that the name in the use statement is not a compound name and does not comply with the rules, so it is "useless ".
Check whether your statement is directly followed by the name of the class or interface after use, such
Use News;
To:
Use YourNameSpace \ News; (this is the same as use YourNameSpace \ News as News)
For the Yii2 framework, the alias reference of the data model is usually similar to the following:
Use app \ models \ News;
If Laravel is used, the alias reference is automatically completed because the app \ models path has been added by default in Composer.
Therefore, you only need to ensure that the class name is correct and no additional use statements are required.
When using the framework, since the latest frameworks all follow the naming conventions for automatic loading of PSR-4,
Therefore, when you use the underscore (_) in a file or path name, it is automatically divided into multiple paths for matching.
By iefreer