简体   繁体   English

Opencart中的语法错误期望标识符

[英]Syntax error expecting identifier in Opencart

I was just checking functionality of opencart's cart controller. 我只是在检查opencart购物车控制器的功能。 Where i saw 我看到的地方

foreach ($results as $result) {
                if ($this->config->get($result['code'] . '_status')) {
                    $this->load->model('total/' . $result['code']);
                    $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
                }
            } 

Its working fine. 它的工作正常。 But when i change it to 但是当我将其更改为

foreach ($results as $result) {
                if ($this->config->get($result['code'] . '_status')) {
                    $this->load->model('total/' . $result['code']);
                    $this->'model_total_' . $result['code']->getTotal($total_data, $total, $taxes);
                    }
            } 

its giving me an error Parse error: syntax error, unexpected ''model_total_'' . 它给了我一个错误Parse error: syntax error, unexpected ''model_total_'' I don't know why this happened. 我不知道为什么会这样。 Does it refer to same or not. 它是否指代相同或不相同。 If not then why i have to use curly braces $this->{'model_total_' . $result['code']} 如果不是,那为什么我必须使用花括号$this->{'model_total_' . $result['code']} $this->{'model_total_' . $result['code']} for it. $this->{'model_total_' . $result['code']} Can anyone explain. 谁能解释。

It is not accepting the concatenation of your result there, so try this, 它不接受您的结果的串联,因此请尝试此操作,

foreach ($results as $result) {
     if ($this->config->get($result['code'] . '_status')) {
         $this->load->model('total/' . $result['code']);
         $code = 'model_total_' . $result['code'];
         $this->$code->getTotal($total_data, $total, $taxes);
     }
}

or 要么

foreach ($results as $result) {
     if ($this->config->get($result['code'] . '_status')) {
         $this->load->model('total/' . $result['code']);
         $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes); // wrap with {}
     }
}

EDIT 编辑

Wrapping with {} is required when you are using array element for concatenation. 当您使用数组元素进行串联时,需要用{}包装。

$this->'model_total_' . $result['code']->getTotal($total_data, $total, $taxes);
                        ^             ^

you are using array element for concatenation, So you are getting error. 您正在使用数组元素进行串联,所以您会遇到错误。

You can even notice that my first example works without {} , because its normal variable. 您甚至可以注意到,我的第一个示例在没有{}情况下可以工作,因为它是普通变量。

如果要使用表达式作为属性名称,则必须将其放在{}除非它只是一个变量。

暂无
暂无

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

相关问题 Symfony2 Doctrine:语法错误,意外'功能',期待'标识符' - Symfony2 Doctrine: syntax error, unexpected 'function', expecting 'identifier' 在 laravel 中使用刀片语法时,语法错误,意外标识符“后端”,期望“)” - syntax error, unexpected identifier "backend", expecting ")"when using blade syntax in laravel 错误:(!)分析错误:语法错误,意外的''(T_ENCAPSED_AND_WHITESPACE),需要标识符(T_STRING) - Error : ( ! ) Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) 为什么这个解析错误在这里解析错误:语法错误,意外标识符“编辑”,期待“,”或“;”? - Why is this parse error here Parse error: syntax error, unexpected identifier "edit", expecting "," or ";"? PHP 中的空白错误,需要标识符 - whitespace error in PHP, expecting an identifier Cakephp 解析错误:语法错误,意外的“类”(T_CLASS),需要标识符(T_STRING) - Cakephp Parse error: syntax error, unexpected 'Class' (T_CLASS), expecting identifier (T_STRING) 解析错误:语法错误,意外的“;”,需要标识符(T_STRING)或变量(T_VARIABLE) - Parse error: syntax error, unexpected ';', expecting identifier (T_STRING) or variable (T_VARIABLE) Wordpress-解析错误:语法错误,意外的“函数”(T_FUNCTION),期望的标识符(T_STRING) - Wordpress - Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) 语法错误,意外'。',期待')' - syntax error, unexpected '.', expecting ')' 语法错误,意外的'[',期望')' - Syntax error, unexpected '[', expecting ')'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM