Home > Backend Development > PHP Tutorial > php empty() error, Fatal error: Can't use function return_PHP tutorial

php empty() error, Fatal error: Can't use function return_PHP tutorial

WBOY
Release: 2016-07-13 10:57:13
Original
880 people have browsed it

Today when I was using the empty function, I got a Fatal error: Can't use function return value in write context error message. I thought it was very strange. I have been using this function for a long time. What happened today? Let's take a look at it. analysis process.

Error message

Fatal error: Can’t use function return value in write context in empty.php on line 5

My code is written like this

It can be seen that empty can only be used to check variable values ​​and cannot be used to check the return value of a function. The correct usage should be
The code is as follows
 代码如下 复制代码

$str=” “;
if(empty(trim($str))){
echo “empty”;
}

Copy code

$str=” “;
if(empty(trim($str))){
echo “empty”;
}

Then it appeared

Fatal error: Can’t use function return value in write context in empty.php on line 5

I couldn’t see the reason so I went to the official website and checked the manual.

bool empty ( mixed $var )
 代码如下 复制代码

$var =trim(” “);
// 结果为 true,因为 $var 为空字符串
if (empty($var)) {
echo ‘empty’;
}

If var is a non-empty or non-zero value, empty() returns FALSE. In other words, "", 0, "0", NULL, FALSE, array(), var $var; and objects without any properties will be considered empty, and TRUE will be returned if var is empty. empty() is the antonym of (boolean) var, except that it does not produce a warning when the variable is not set.

The code is as follows

Copy code
$var =trim(” “);
// The result is true because $var is an empty string
if (empty($var)) {
echo ‘empty’;
} The usage of empty(trim($str) is wrong. http://www.bkjia.com/PHPjc/632096.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632096.htmlTechArticleToday when using the empty function, a Fatal error: Can't use function return value in write context error message appeared, I think It's strange. I have been using this function for N long. What happened today...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template