【发布时间】:2016-03-30 14:10:20
【问题描述】:
我已经定义了一个$foo 全局变量。
稍后,我想将$foo 设置为其他值。
public function bar()
{
global $foo;
$foo = 'hello';
}
将其缩短为一行是否有任何意想不到的副作用?
public function bar()
{
global $foo = 'hello';
}
我查看了the documentation 并没有看到他们在同一行声明和分配变量。因此,我想知道是否有其他人在这样做时遇到过问题,或者将它放在一行中是否只是一种糟糕的编码习惯?
【问题讨论】:
标签: php global-variables global