For php development, the empty function (note: In fact, empty is a language structure rather than a function. here, the function is just a personal habit) is a familiar function, the following is a description of the PHP Manual: 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 code based on others' experience:
The code is as follows:
Echo"
";
$ Tokens = token_get_all ('
');
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
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!
(Similar to print, echo, include, require, die, etc., they are all language structures. in some online articles, if print has a returned value, it is said that the function is incorrect)