Home > Backend Development > PHP Tutorial > Solution to PHP empty function error_PHP tutorial

Solution to PHP empty function error_PHP tutorial

WBOY
Release: 2016-07-13 10:37:10
Original
902 people have browsed it

When developing in PHP, when you use empty to check the result returned by a function, an error will be reported: Fatal error: Can't use function return value in write context

For example, the following code:

Copy the code The code is as follows:

echo empty( strlen('test'));

Go to the PHP manual and see the following text where the empty function is described:

Copy the code The code is as follows:
Note : empty() only variables checks as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).

Conclusion: empty() only Detecting variables, testing anything that is not a variable will result in a parsing error!

Therefore, we cannot use empty to directly detect the value returned by the function. The solution to the above example is as follows:

Copy the code The code is as follows:

$length = strlen('test');
echo empty($length);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736792.htmlTechArticleWhen developing PHP, when you use empty to check the result returned by a function, an error will be reported: Fatal error: Can't use function return value in write context For example, the following code: Copy code code...
Related labels:
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