所以,我有一些这样的代码:
$xml = simplexml_load_file( $configuration_path . $this->configuration_file );
// some stuff in between, not important
// next line would be line 80, where the parser whines
$this->ping_tree_1 = ( string ) (( $xml->xpath( '//ping-tree[@order="1"]' ))[0] );
现在,它对我来说似乎足够有效,但我不断收到此错误:
Parse error: syntax error, unexpected '[' in models/site_configuration.php on line 80
如果我注释掉违规行并执行以下操作:
print_r( $xml->xpath( '//ping-tree[@order="1"]' ));
die;
我看到以下内容被返回:
Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[order] => 1
)
[0] => dd0d7afa2414fc1d3ddc18c87351478f
)
)
这正是我所期望的。
然而,更有趣的是,当我这样做时:
$_xml = $xml->xpath( '//ping-tree[@order="1"]' );
$this->ping_tree_1 = ( string ) $_xml[0];
一切正常!
那么......什么给了?有人有线索吗?这是一个 PHP 解析错误,还是只是我很密集?
顺便说一句,这一切都在 Apache/2.2.22 (Unix) 下的 PHP/5.2.17 上。
谢谢!