Home > Backend Development > PHP Problem > What to do if php empty error occurs

What to do if php empty error occurs

藏色散人
Release: 2023-03-05 13:02:01
Original
2439 people have browsed it

php empty error is because empty only detects variables. Detecting anything that is not a variable will result in a parsing error. The solution is to directly detect the value returned by the function without using empty. The code is such as "$length=strlen ('test');echo empty($length);".

What to do if php empty error occurs

Recommendation: "PHP Video Tutorial"

Solution to error reported by PHP empty function

Solution to the error reported by PHP empty function when detecting a non-variable.

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:

<?php 
echo empty(strlen(&#39;test&#39;));
Copy after login

Go to the PHP online manual to view. In the description of the empty function, there is the following text:

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

Conclusion: empty() only detects variables and detects any non- Variables will cause parsing errors!

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

<?php
$length = strlen(&#39;test&#39;);
echo empty($length);
Copy after login

The above is the detailed content of What to do if php empty error occurs. For more information, please follow other related articles on the PHP Chinese website!

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