因此,当我在基于CentOS的Apache web服务器上部署时,试图访问我的测试站点时,会出现此错误:
Fatal error: Can't use method return value in write context in /var/www/betadmin/src/AdminBundle/Twig/WidgetTwigExtension.php on line 234
第234行包含以下内容:
if(empty($session->get('currency'))) {
这是整个代码:
public function get_default_currency()
{
$session = new Session();
if(empty($session->get('currency'))) {
$currency = $this->currencyService->findOneByDefault();
if(!$currency instanceof Currency) {
$currency = $this->currencyService->findOneByName('EURO');
if(!$currency instanceof Currency) {
$currency = $this->currencyService->findOneByActive();
if(!$currency instanceof Currency) {
$currency = $this->currencyService->findOneByInactive();
if(!$currency instanceof Currency) {
//$currency = array ('currency' => 'None');
return 'None';
}
}
}
}
$session->set('currency', $currency);
}
return $session->get('currency');
}
事实上,空函数不接受直接计算函数返回值。Empty()不是语言的函数,而是一种语言构造。
尝试:
public function get_default_currency()
{
$session = new Session();
$ret = $session->get('currency');
if(empty($ret)) {
$currency = $this->currencyService->findOneByDefault();
if(!$currency instanceof Currency) {
$currency = $this->currencyService->findOneByName('EURO');
if(!$currency instanceof Currency) {
$currency = $this->currencyService->findOneByActive();
if(!$currency instanceof Currency) {
$currency = $this->currencyService->findOneByInactive();
if(!$currency instanceof Currency) {
//$currency = array ('currency' => 'None');
return 'None';
}
}
}
}
$session->set('currency', $currency);
}
return $session->get('currency');
}