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

Solution to PHP empty function error_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:37:10850browse

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...
Statement:
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