在官方手册上没有找的这种写法的意思?
<code class="php">namespace {
$test = 'a';
}
namespace {
if($test == 'a'){
//do something
}
}</code>在官方手册上没有找的这种写法的意思?
<code class="php">namespace {
$test = 'a';
}
namespace {
if($test == 'a'){
//do something
}
}</code>
可以看看,以前优化的时候,用过这个方式,将框架多个文件合并成一个。
手册地址是: http://php.net/manual/zh/language.namespaces.definitionmultiple.php
我本地自己试了一次,发现一个问题
<code>namespace a
{
class abc
{
private $test = 'a';
public function ceshi()
{
echo $this->test;
}
}
}
namespace {
$ceshi = new a\abc();
$ceshi->ceshi();
}
</code>和
立即学习“PHP免费学习笔记(深入)”;
<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>意义差不多 第一种是全局调用
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号