【发布时间】:2013-01-23 08:13:35
【问题描述】:
我有一个如何调用变量的问题。
在Js中,如果我在B()里面写$A = $this->A,我可以通过$A里面C()到达$this->A;但在 PHP 中似乎这种方式行不通。
请建议一种可以在 C() 内部读取 $this-A 而无需给出函数变量的方法。
class X {
function B(){
function C(){
$this->A; // Can not call A here
$A; // No work either
}
$A = $this->A; //
$this->A; // Can call A here
}
private $A;
}
这里是Global $A
Get variables from the outside, inside a function in PHP
但是,如果是全局的,这里的全局是指整个脚本不在类内。
非常感谢您的建议。
【问题讨论】: