During PHP development, when you use empty to check the results returned by a function, the following error occurs: Fatal error: Can't use function return value in write context.
For example, the following code:
Copy codeThe Code is as follows:
<? Php
Echo empty (strlen ('test '));
Go to the PHP manual and check the following text in the description of the empty function:
Copy codeThe Code is as follows: 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 any non-variables will cause parsing errors!
Therefore, we cannot use empty to directly detect the value returned by the function. The solution in the preceding example is as follows:
Copy codeThe Code is as follows:
<? Php
$ Length = strlen ('test ');
Echo empty ($ length );