PHP alias reference error: "Theusestatementwithnon

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.