我的一个类中有一个方法,看起来像,
public function render() {
foreach ($this->_levels as $level) {
ob_start();
$path = $_SERVER['DOCUMENT_ROOT'] . '/' . $level[0] . '/' . $level[1] . '.php';
if (file_exists($path)) {
require($path);
}
$content = ob_get_clean();
if ($content) {
$this->_content = $content;
}
}
return $this->_content;
}
在包含的文件中,我可以访问$this
。无论如何,我可以导致这种情况发生吗? (所以$this
没有定义?)
我已尝试将其包装在匿名函数中并绑定到null但它不起作用。