简体   繁体   English

解析错误:语法错误,意外的 '[',期待 ')' php

[英]Parse error: syntax error, unexpected '[', expecting ')' php

I am creating a custom shipping method for opencart, however i am stuck on the catalog model file, which is for PHP 5.4+ , but how do i make it working with PHP 5.3 as Opencart Requirement is start from PHP 5.3我正在为 opencart 创建自定义运输方法,但是我被困在目录模型文件上,该文件适用于PHP 5.4+ ,但是我如何使它与PHP 5.3一起使用,因为 Opencart 要求是从 PHP 5.3 开始的

catalog/model/shipping/items.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')))
    );

this line working fine with PHP 5.4+ but not PHP 5.3这条线在 PHP 5.4+ 上工作正常,但在 PHP 5.3 上不工作

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

I get an error for PHP 5.3 which is我收到 PHP 5.3 的错误消息

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

I've also read many duplicate question and tried many different way to make this working with no luck!我还阅读了许多重复的问题,并尝试了许多不同的方法来使这个工作没有运气! please help, thank you!请帮忙,谢谢!

Just assign it to variable: $description = $this->config->get('items_shipping_description') And then use:只需将其分配给变量: $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')))
);
$this->config->get('items_shipping_description')[$languages]

This is function array dereferencing and was only added in php 5.4这是函数数组解引用,仅在php 5.4 中添加

To make it work with php 5.3 you will need to assign that return value to a variable and then use that.要使其与 php 5.3 一起使用,您需要将该返回值分配给一个变量,然后使用它。

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

Try this,尝试这个,

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

And

'title'        => $desc[$languages],

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP解析错误:语法错误,意外的“:”,期待“;” 或者 '{' - PHP Parse error: syntax error, unexpected ':', expecting ';' or '{' 解析错误:语法错误,意外的'[',期望')',可能是PHP版本问题 - Parse error: syntax error, unexpected '[', expecting ')', possibly PHP version issue Wordpress插件PHP解析错误:语法错误,意外的“ {”,预期为“)” - Wordpress plugin PHP Parse error: syntax error, unexpected '{', expecting ')' 解析错误:语法错误,意外的';',期望的是')'(Wordpress functions.php) - Parse error: syntax error, unexpected ';', expecting ')' (Wordpress functions.php) PHP 版本 4:: 解析错误:语法错误,意外 '=',期待 ')' - PHP version 4 :: Parse error: syntax error, unexpected '=', expecting ')' PHP解析错误:语法错误,意外的T_IS_EQUAL,预期 - PHP Parse error: syntax error, unexpected T_IS_EQUAL, expecting 的PHP-语法错误,意外的'(',期待')' - php - syntax error, unexpected '(', expecting ')' 解析错误:语法错误,意外'(',期待','或';'in - Parse error: syntax error, unexpected '(', expecting ',' or ';' in 解析错误:语法错误,意外的'{',需要'('帮助? - Parse error: syntax error, unexpected '{', expecting '(' help? PHP解析错误:解析错误,意外的“ *”,期望为“}” - PHP Parse error: parse error, unexpected '*', expecting '}'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM