Why not & amp; lt ;? Php {code ...}? & Amp; gt; must be written as & amp; lt ;? Php {code ...}? & Amp; gt; why not
Function done () {require_once 'vendor/autoload. php'; use Qiniu \ Auth; use Qiniu \ Storage \ UploadManager; # omitted}
?>
Must be written
Require_once 'vendor/autoload. php'; use Qiniu \ Auth; use Qiniu \ Storage \ UploadManager; function done () {# omitted}
?>
Reply content:
Why not?
Function done () {require_once 'vendor/autoload. php'; use Qiniu \ Auth; use Qiniu \ Storage \ UploadManager; # omitted}
?>
Must be written
Require_once 'vendor/autoload. php'; use Qiniu \ Auth; use Qiniu \ Storage \ UploadManager; function done () {# omitted}
?>
Because of the language structure, if you know the nature of the PHP namespace, I don't think so.
use
The function is only to replace a long name with a short name, or to replace the original name with an alias.Syntactic sugar".
So eliminateuse
Is a very reasonable choice. Therefore, php requiresuse
It is processed in the parsing phase (parse.
Execute on-site (equivalent to a statement) only when runningecho
,require
And so on,use
The language structure is pre-scanned and pre-processed in the parsing (parse) phase.. The above is the premise.
WhileAnalysisThe operation itself is very simple. It only starts from the beginning to the end, recognizes language keywords one by one, and ensures that the syntax rules are not violated. We can do a simple experiment:
I don't know if Zima will use my face to roll the keyboard, but I know that php won't let me parse it --
Do you say 5th rows will never be executed? The parser does not know or care about it.
But for a scope enclosed by curly braces, things become complicated. Because the execution sequence of a small scope is likely to be messy-you can go back, you can jump through the call, and so on. For example:
namespace NS1;class ClassName { }function f() { return new ClassName();}for ($i=0; $i<2; $i++) { $a = new ClassName(); $b = f(); use NS2\ClassName; $c = new ClassName();}
If we thinkuse
Will affect all the content behind it, then at this time$a
And$b
The value assignment statement is not inuse
Behind?
According to the semantics, 1st cycles are not there, and 2nd cycles are there. That is to say, the same row produces two different semantics.
However, the parser cannot understand or maintain this logic. To implement this logic, it will inevitably generate a runtime overhead (because it is necessary to intervene in the status that can be determined only when the program is running). This isuse
Designed to avoid.
Souse
It can only be placed in the outermost scope of the file. Only the scope of this scope is a one-line push. It is impossible to roll back or jump.
Try to analyze the followinguse
The true scope can be seen that in the logic, everything is designed to facilitate the parser processing:
Slaveuse
Start of the row that appears (simple start rule)
Seenamespace
End (simple termination rule)
End at the end of the file (the parser cannot run across files)
In fact, it is similar to rigorous design and interlockingLanguage FeaturesDifferent, manySyntactic sugarThere is not much truth to explain.
Energy Imaginguse
In this way, from the initial design purpose, it is quite rare to deduce the syntactic sugar that is inevitably limited by its design.
For syntactic sugar, this is what we use as a language user.