What does {code...} mean? In my experiment, I understand that a non-qualified name means that no prefix is added when calling functionclass $, that is, the class or $ or function in the file where the code is located. Is that correct?
A non-qualified name or a class name that does not contain a prefix, for example, $ a = new foo (); or foo: staticmethod ();. If the current namespace is currentnamespace, foo will be parsed as currentnamespace \ foo. If the code using foo is global and is not included in any namespace, foo will be parsed as foo. Warning If the function or constant in the namespace is not defined, the undefined function name or constant name will be resolved to the global function name or constant name.
What does this mean? My experiment comprehension:
Unrestricted name
That is, when calling function class $, no prefix is added,
This is to call the class, $, or function in the file where the code is located. Is that correct?
Reply content:
A non-qualified name or a class name that does not contain a prefix, for example, $ a = new foo (); or foo: staticmethod ();. If the current namespace is currentnamespace, foo will be parsed as currentnamespace \ foo. If the code using foo is global and is not included in any namespace, foo will be parsed as foo. Warning If the function or constant in the namespace is not defined, the undefined function name or constant name will be resolved to the global function name or constant name.
What does this mean? My experiment comprehension:
Unrestricted name
That is, when calling function class $, no prefix is added,
This is to call the class, $, or function in the file where the code is located. Is that correct?
Check the source code.
Namespace Project \ Model; // This file belongs to the namespace Project \ Model. If no special description is provided, the classes that will appear later will be the classes in this space, for example, User indicates \ Project \ Model \ User, Table \ User indicates \ Project \ Model \ Table \ Useruse Zend \ Table; // calls the \ Zend \ Table class, when you use this declaration and then call $ table = new Table ();, this Table refers to \ Zend \ Tableuse Project \ Model \ Table PTable; // call the \ Project \ Model \ Table class and specify the alias PTable. When $ table = new PTable (); is called, this PTable indicates that the Project \ Model \ Table // is declared in the above Code, the absolute path class User extends \ Project \ Model {// User is not specified, so the full name of this class is \ Project \ Model \ User, \ Project \ Model refers to the class \ Project \ Model (cannot be written as extends Model; otherwise it is considered as \ Project \ Model) because it starts with a backslash )} class \ User extends Table \ User {// starts with a backslash. Therefore, the full name of this class is \ User, and the User following this class does not have a slash, \ Project \ Model \ Table \ User}
It can be seen that for namespace and use statements, the class uses the full name, and must start with a backslash to indicate the full name of the class elsewhere, otherwise, the full name is a backslash + the current namespace + class name.
In layman's terms: namespace is the location information of a file (globally unique)
For example
lib/pay/weixin.php lib/order/weixin.php
The space of the two weixin. php instances is different.
The namespace is used to solve the problem of duplicate class names.
You don't need to do the experiment. It will make you dizzy.