题
我试图使用PHP 5.3.2抛出一个异常,这是给我下面的错误:
解析错误:语法错误,意想不到T_THROW
我试图抛出异常方式如下:
throw new Exception('Property ' . $name . ' doesn\'t exist in class Index', '');
编辑:我也尝试
throw new Exception('Property ' . $name . ' doesn\'t exist in class Index');
它并没有改变我正在错误。
完整的方法:
public function __get($name)
{
if(property_exists($this, $name)
throw new Exception('Property ' . $name . ' doesn\'t exist in class Index');
return $this->$name;
}
解决方案
检查PHP代码为NG片段,有时我错过断“;”这可能会导致错误。
也尝试写正式的if语句,将在括号中。我知道这不应该使任何可能性,但谁与编程知道!
其他提示
您缺少你如果()线的关闭括号等PHP认为这
if(property_exists($this, $name) throw new Exception(...);
这是无效的语法。代替)在你如果()行的末尾:
if(property_exists($this, $name))
编辑:我讨厌当我错过一个答案下面的答复。 :(
不隶属于 StackOverflow