【发布时间】:2017-06-13 06:56:50
【问题描述】:
我找到了一个 PHP 库,其中一行是:
$this->get_soap_provider_options()['location'];
但这会产生错误:
Parse error: syntax error, unexpected '[' in ...path to file.. at line...
我不明白为什么['location'] 写在函数参数get_soap_provider_options() 之后。应该是 get_soap_provider_options('location') 或 get_soap_provider_options(array('location')) 或类似的东西。
我认为这行代码适用于 PHP 5.4 或更高版本。如何为旧版本的 PHP 编写此行?
【问题讨论】:
-
get_soap_provider_options()返回一个数组,您尝试通过键location访问一个值(在数组内)。 -
php.net/manual/en/…,示例 7。
-
Tom,如何为旧版本(5.4 之前)编写 $this->get_soap_provider_options()['location'] 行?因为在关闭参数大括号之后,在旧版本的php中不允许写
['location']。应该是这样的:$this->get_soap_provider_options('location')或者$this->get_soap_provider_options(array('location')).......怎么写? -
尝试将函数的结果存储在变量中,并通过变量访问值。
-
我不明白为什么 ['location'] 写在函数 agrument get_soap_provider_options() 之后。它应该是 get_soap_provider_options('location') 或 get_soap_provider_options(array('location')) 或类似的东西。