Determine whether a variable is considered to be empty.
But in my memory, for a long time I thought that empty should be able to judge whether something is empty until one day I am like this "EMPTY (TRIM ($ )) "an error occurs during use, and then you can check the manual to find out that the empty function can only judge whether a variable is null, rather than a string (or other values, including the function return value) is empty. Although I know that this is only a reason for the surface layer, I have not understood the underlying reasons.
Recently, I became interested in the PHP kernel and remembered this problem again. So I wrote the following section based on others' experience: Code :
Copy code The Code is as follows: <? PHP
Echo "<PRE> ";
$ Tokens = token_get_all ('<? PHP empty (TRIM ($ A);?> ');
Foreach ($ tokens as $ t ){
If (is_array ($ t )){
Printf ("% s \ t % s \ n", token_name ($ t [0]), htmlspecialchars ($ t [1]);
} Else {
Printf ("\ t % s \ n", $ t );
}
}
The result is as follows: (if you do not understand this, take a look at the "List of parser tokens" section in the appendix of the PHP manual)
T_open_tag <? PHP
T_empty empty
(
T_string trim
(
T_variable $
)
)
T_close_tag?>
The token corresponding to the variable should be t_variable, while trim ($ A) corresponds to t_string. Therefore, if you run "empty (TRIM ($ A);" directly, the following error occurs:
Fatal error: Can't use function return value in write Context
Then I want to directly use empty as a string. What will happen? The result is not a running error, but a parsing error:
Parse error: Parse error, expecting 't_ string' or 't_ variable' or ''$'' in...
(I think this error message is confusing ...)
Check that the token corresponding to the string is t_constant_encapsed_string (string syntax ). Although the parameters have different token values, they are not t_variable. They should be correct only when an error occurs during the compilation phase...
So I also learned to view the PHP source code for those high people... But I haven't read the relevant code yet ~
The last time I reiterate that empty is a language structure rather than a function!
(Like print, Echo, include, require, die, etc., they are all language structures.ArticleIf print has a returned value, it means that the function is incorrect)