我在PHP5.4上运行以下行没有任何问题:
$lstContent = $data->xpath("/response/lst[@name='highlighting']")[0]->lst[$i]->arr->str;
但是现在在PHP5.3(生产系统)上我收到以下错误:
解析错误:语法错误,意外' ['在第153行的/var/www/html/upload/inc_suche_code.php中
快速修复的想法? 更新PHP对我来说不起作用。
答案 0 :(得分:6)
在旧版本的PHP中,您无法直接访问作为函数结果的变量的数组值。您必须使用临时变量拆分表达式。
$result = $data->xpath("/response/lst[@name='highlighting']");
$lstContent = $result[0]->lst[$i]->arr->str;
从PHP 5.4开始,可以直接对函数或方法调用的结果进行数组取消引用。之前只能使用临时变量。
来源:http://php.net/manual/en/language.types.array.php
编辑:必须"您还应该考虑升级您的PHP版本"。这个烦人的限制是在很久以前修复的,更不用说5.3有end of life in 2014,这意味着它从那时起就没有得到安全升级。