我得到了以下错误,我似乎不知道为什么或如何被触发。
Fatal error: Cannot access empty property in /home/content/p/l/a/plai1870/html/com/php/Bone/Compiler.php on line 18
第18行是
throw new LogicException($this->$compilers[$language]." is not a supported compiler.");这是Compiler.php
<?php
namespace Bone;
use LogicException;
class Compiler implements \Bone\Interfaces\Compiler {
protected $compiler;
protected $compilers = array(
"php" => "PHP",
"as3" => "ActionScript3",
"javascript" => "Javascript"
);
public function __construct($language) {
$language = strtolower($language);
if (!isset($this->$compilers[$language])) {
throw new LogicException($this->$compilers[$language]." is not a supported compiler.");
}
$compiler = "\Bone\Compilers\\".$this->$compilers[$language]."\Compiler";
$this->compiler = new $compiler();
}
public function buildDefinition($object, $path = null) {
return $this->compiler()->buildInterface($object, $path);
}
public function buildObject($object, $path = null) {
return $this->compiler->buildObject($object, $path);
}
public function parameters($method) {
return;
}
public function save($data, $path) {
return;
}
}
?>编辑,我用以下方式调用它:
$compiler = new \Bone\Compiler("php");发布于 2012-11-07 16:27:38
抱歉,如果这是最明显的,但是:
throw new LogicException($this->$compilers[$language]." is not a supported compiler.");由于已检查该属性不存在,因此不应该:
throw new LogicException("$language is not a supported compiler.");编辑:
$this->$compilers[$language]
^- variable property移除$:
$this->compilers[$language]然后,您可以检查数组中的条目是否已设置,而不是是否设置了(unset)数组$compilers (局部变量)中值名称的属性。
在开发时,请始终打开警告和通知(可以想象的最高错误级别),在没有PHP警告的情况下不会遇到这些问题。
发布于 2012-11-07 16:31:20
您的数组是$this->compilers,而不是$this->$compilers。
函数中不存在$compilers,因此$this->$compilers正在寻找一个空白属性。
https://stackoverflow.com/questions/13273905
复制相似问题