这是在 PHP 5.3 中给我错误的行,它在 php 5.4 中完美运行
if ($user->getGeoCode()) {
$latitude = $user->getGeoCode()['latitude'];
}
错误信息是:
Parse error: syntax error, unexpected '[' in IndexController.php on line 29
这是我的用户类:
class User {
.....
public function getGeoCode() {
$geoCode=array();
if ($this->getAddress() && $this->getCity() && $this->getCountry()) {
$address = urlencode($this->getAddress() . ' ' . $this->getCity() . ' ' . $this->getPostalCode() . ' ' . $this->getCountry()->getName());
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=' . $address . '&sensor=false');
$output = json_decode($geocode);
if ($output->status=='OK') {
$geoCode['latitude']=$output->results[0]->geometry->location->lat;
$geoCode['longitude']=$output->results[0]->geometry->location->lng;
return $geoCode;
}
else {
return null;
}
}
else {
return null;
}
}
}
此错误与 PHP 版本有关吗?