简体   繁体   English

Prestashop模块奇怪的问题

[英]Prestashop module weird issue

I am developing a custom module in prestashop. 我正在prestashop开发一个自定义模块。 In that I have taken value inside a function like this 因为我在这样的函数中取得了价值

$fname = !empty(Tools::getValue('fname')) ? Tools::getValue('fname') : '';

but its showing error like this 但它显示这样的错误

Fatal error: Can't use function return value in write context

So can someone tell me why the error is here? 那么有人可以告诉我为什么错误在这里? How to solve this issue? 如何解决这个问题?

I got the answer. 我得到了答案。 It should be like this 它应该是这样的

Tools::getValue('fname') ? Tools::getValue('fname') : ' ';

I just will explain it here for someone from google results. 我只是在这里为谷歌搜索结果的人解释。

  1. empty(someFunction()) creates error, because empty(someFunction())创建错误,因为

Note: Prior to PHP 5.5, empty() only supports variables; 注意:在PHP 5.5之前,empty()仅支持变量; anything else will result in a parse error. 其他任何东西都会导致解析错误。 In other words, the following will not work: empty(trim($name)). 换句话说,以下将不起作用:empty(trim($ name))。 Instead, use trim($name) == false. 相反,使用trim($ name)== false。

http://php.net/manual/en/function.empty.php http://php.net/manual/en/function.empty.php

  1. In Prestashop method Tools::getValue() have possibility to use default value, 在Prestashop方法中, Tools::getValue()有可能使用默认值,

    public static function getValue($key, $default_value = false) { public static function getValue($ key,$ default_value = false){

so you can use Tools::getValue('fname', ''); 所以你可以使用Tools::getValue('fname', ''); and returned value will contain or value of 'fname' or empty string, in this case. 在这种情况下,返回值将包含'fname'或空字符串的值或值。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM