2015-10-29 104 views
-2

我創造Opencart的自定義送貨方式,但我卡在目錄模型文件,該文件是爲PHP 5.4+我,但我怎麼使它與PHP 5.3工作作爲Opencart的要求是從PHP 5.3開始
解析錯誤:語法錯誤,意想不到的「[」,預計「)」 PHP

目錄/模型/運輸/ items.php

$languages = $this->language->get('code'); 
    $quote_data = array(); 
    $quote_data['items'] = array(
     'code'   => 'items.items', 
     'title'  => $this->config->get('items_shipping_description')[$languages], 
     'cost'   => $this->config->get('items_cost'), 
     'tax_class_id' => $this->config->get('items_tax_class_id'), 
     'text'   => $this->currency->format($this->tax->calculate($items_cost, $this->config->get('items_tax_class_id'), $this->config->get('config_tax'))) 
    ); 

這一行工作的罰款與PHP 5.4+而不是PHP 5.3

我得到PHP 5.3的錯誤是

Parse error: syntax error, unexpected '[', expecting ')' in ... 

我也看到了許多重複的問題,嘗試了很多不同的方式,使這個沒有運氣的工作!請幫忙,謝謝!

+1

*第一*谷歌命中問題的*標題*:http://stackoverflow.com/questions/17411106/parse-error-syntax-error-unexpected-expecting –

+2

[PHP語法的可能的複製解引用函數的結果(http://stackoverflow.com/questions/742764/php-syntax-for-dereferencing-function-result) –

+0

@karoly霍瓦特:這是我讀過的第一個問題,順便說一句謝謝 –

回答

3

只是把它分配給變量: $description = $this->config->get('items_shipping_description') 然後用:

$quote_data['items'] = array(
    'code'   => 'items.items', 
    'title'  => $description[$languages] 
    'cost'   => $this->config->get('items_cost'), 
    'tax_class_id' => $this->config->get('items_tax_class_id'), 
    'text'   => $this->currency->format($this->tax->calculate($items_cost, $this->config->get('items_tax_class_id'), $this->config->get('config_tax'))) 
); 
+0

謝謝!它現在的工作,從來不想着做這種方式,我只是與陣列()的東西玩,順便說一句沒有這個代碼,也可以使用了PHP5.4 +? –

+0

@Zulfakar Zukri,是的,它可以使用。 – sergio

0

試試這個,

$desc = $this->config->get('items_shipping_description'); 

而且

'title'  => $desc[$languages], 
1
$this->config->get('items_shipping_description')[$languages] 

這是函數數組解引用,只添加在php 5.4

爲了使它與php 5.3一起工作,您需要將該返回值分配給一個變量,然後使用它。

$items = $this->config->get('items_shipping_description'); 
$items[$languages]; 
相關問題