Bohemian Rhapsody PHP empty function usage Instructions

Source: Internet
Author: User
Tags parse error
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.