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 tell if something was empty, until one day I had an error like "Empty ($a)" used, Then we'll find out the manual. The original empty function can only determine whether a variable is empty, but not a string (or other value, including the function return value) is empty. Although I know that this is only a superficial reason, but not to understand the deep-seated reasons.
Recently interested in the PHP kernel, and again think of this problem, so according to the experience of others wrote the following code:
Copy the Code code 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 output is as follows: (If you don't understand, look at the "List of Parser Tokens" section of the PHP manual appendix)
T_open_tag
T_empty EMPTY
(
T_string Trim
(
T_variable $a
)
)
T_close_tag?>
The token corresponding to the variable should be t_variable, while trim ($a) corresponds to t_string. So if you run "empty" (Trim ($a)) directly; Causes a Run Error:
Fatal Error:can ' t use function return value in write context
Then I want to empty a string directly what will happen? The result is not a run error, but a parse error:
Parse error:parse error, expecting ' t_string ' or ' t_variable ' or ' ' $ ' in ...
(Feeling this error message makes people ... )
The token corresponding to the view string is t_constant_encapsed_string (string syntax). Although the parameters for the token are different, but they are not t_variable, should be in the compile phase of the error in the right, why ...
So also learn the high people to see the source of PHP ... But have not read the relevant code, hehe, next time to share ~
Finally, empty is a language structure, not a function!
(and Print,echo,include,require,die, and so on is the language structure, some articles on the web said that print has a return value is said to be a function is wrong)The above describes the Bohemian rhapsody php empty function instructions, including the Bohemian Rhapsody aspects of the content, I hope that the PHP tutorial interested in a friend helpful.