PHP empty function 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 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)

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.