【发布时间】:2012-09-15 07:51:43
【问题描述】:
我有一个像下面这样的 PHP 类
<?php
class Test{
var $conf = array('a' => 1, 'b' => 2, c => 3);
private function do_something(){
// Do something Here
function do_something_else(){
// How to get the variable value for $conf ???? o.O
}
}
}
?>
我想在函数do_something_else() 中访问$conf。在上层函数中,我可以以$this->conf 访问它,但我猜$this 在内部函数中不可用。访问该函数内的变量的最佳方法是什么?
我无法传递值,因为该函数将由 WordPress CMS 中的内置函数调用,因此此处不能选择传递参数。
【问题讨论】:
-
请不要。嵌套函数可能看起来干净,但事实并非如此。嵌套函数与普通函数相同(即它们是全局函数),但仅在调用父函数时才定义。再说一遍,请不要。
标签: php class function variables