PHP The empty function reports an error solution
- 2021-01-25 07:15:48
- OfStack
Fatal error: Can't use function return value in write context 'Fatal: Can't use function return value in write context: Can't use function return value write context
Take the following code for example:
<?php
echo empty(strlen('test'));
Go to the PHP manual and see the following text in the empty function description:
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)).
It is concluded that empty() only detects variables, and detecting 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 is as follows:
<?php
$length = strlen('test');
echo empty($length);