0 php
有可能复制这样的变量吗?
class Colours {
var $var = "one";
var $var2 = array('something', $var);
}
Run Code Online (Sandbox Code Playgroud)
最好的方法是在Colours类的构造函数中执行此操作.我不确定PHP,但在其他语言中,不应依赖变量初始化的顺序.
class Colours
{
private $var;
private $var2;
public function __construct()
{
$this->var = "one";
$this->var2 = array('something', $this->var);
}
}
Run Code Online (Sandbox Code Playgroud)