最近使用ThinkPHP時發現不能調用$this->error()方法,總是提示錯誤:
syntax error, unexpected ')', expecting T_VARIABLE or '$'
並且錯誤位置在緩存文件中,特別糾結,這個bug調好幾天了,知道查看log文件才知道是內部解析出的錯誤.
錯誤在ThinkPHP/Lib/Template/TagLib.class.php 的parseXmlAttr函數中:
$xml = (array)($xml->tag->attributes());
$array = array_change_key_case($xml['@attributes']);
替換爲:
$array = array();
foreach($xml->tag->attributes() as $a=>$b) {
$array[$a] = $b;
}
問題解決。
由此發出感想:在出現錯誤時不能完全看它提示的所理解,要在日誌文件Log中找到錯誤位置,
日誌文件必不可少,對於我們查找錯誤和解決問題幫助非常大。