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);".
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('test'));
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)).
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('test'); echo empty($length);
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!