PHP Alias Reference error: "The use statement with Non-compound name ... has no effect" ____php

Source: Internet
Author: User
Tags aliases
Alias Overview

php5.3+ Support namespaces: namespace, one of the important functions of namespaces is that you can use aliases to refer to a rule-compliant name.

Namespaces support the form of alias references in 3 (or referred to as introduction): Class Alias, Interface (interface) alias, and Namespace (namespace) name alias.

php5.6+ also supports function aliases and constant aliases.

(Note: The Php.net website on the alias of this paragraph of the Chinese description of ambiguity and error, more as above) the specific grammatical format

Use xxx\xxx\xxx as XX;

So the use statement is actually an alias reference, not the usual import. Then the name that appears after the use has to be the alias that matches the rule. Errors and Causes

Now look at the error message similar to the title of the article:

"The use statement with Non-compound name ... has no effect"

We can understand this error message is that the name that appears in the USE statement is not a compound name and does not conform to the rule, so it is "no use."

Check that your statement is not directly following the use of the name of the class or interface, such as

Use News;

Modified to:

Use Yournamespace\news; (This is the same as use Yournamespace\news as News)

In the case of the YII2 framework, the alias reference for the typical data model is similar to the following:

Use App\models\news;

If it is Laravel, the alias reference is automatically completed because the App\models path has been added by default in composer.

So just make sure the class name is correct and no additional use statements are required.

When using frames, because the latest frameworks follow the PSR-4 automatic load naming conventions,

So be careful that the use of the underline (_) in the file, the path name, is automatically decomposed into multiple paths to match.


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.