简体   繁体   中英

Prestashop module weird issue

I am developing a custom module in 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

Note: Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

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

  1. In Prestashop method Tools::getValue() have possibility to use default value,

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

so you can use Tools::getValue('fname', ''); and returned value will contain or value of 'fname' or empty string, in this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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