What is the meaning of this writing method that is not found in the official manual?
<code class="php">namespace { $test = 'a'; } namespace { if($test == 'a'){ //do something } }</code>
What is the meaning of this writing method that is not found in the official manual?
<code class="php">namespace { $test = 'a'; } namespace { if($test == 'a'){ //do something } }</code>
You can take a look. When optimizing before, I used this method to merge multiple files of the framework into one.
The manual address is: http://php.net/manual/zh/language.namespaces.definitionmultiple.php
I tried it locally and found a problem
<code>namespace a { class abc { private $test = 'a'; public function ceshi() { echo $this->test; } } } namespace { $ceshi = new a\abc(); $ceshi->ceshi(); } </code>
and
<code>namespace a; class abc { private $test = 'a'; public function ceshi() { echo $this->test; } } namespace b; class abc { private $test = 'b'; public function ceshi() { echo $this->test; } } use a; $ceshi = new a\abc(); $ceshi->ceshi();</code>
The meaning is almost the same. The first one is global call