PHP note:empty () only checks variables as anything error _php tutorial

Source: Internet
Author: User
Tags parse error
Today, using the empty () function to determine if a variable is null is the discovery hint Note:empty () only checks variables as anything else would result in a parse error. In other words, the following would not Work:empty (trim ($name)). Wrong, after a whole day to find the problem.


When you use empty to check the results returned by a function, a fatal error is reported as follows:

Fatal Error:can ' t use function return value in the write context in: ..... .....

For example:

echo Empty (YourFunction (xx, oo));

To the PHP manual, where the empty function describes the following text:

Note:empty () Only checks variables as anything else would result in a parse error. In other words, the following would not Work:empty (trim ($name)).

Empty () detects only variables and detects anything that is non-variable will result in parsing errors!

Therefore, we can not take empty to directly detect the value returned by the function, we need to first assign the return value of the function to a variable, and then to use empty to detect the variable.

So, we can write the following form:

$return = YourFunction (xx, oo);

echo empty (return);

http://www.bkjia.com/PHPjc/633171.html www.bkjia.com true http://www.bkjia.com/PHPjc/633171.html techarticle today, using the empty () function to determine if a variable is null is the discovery hint Note:empty () only checks variables as anything else would result in a parse error. In other words, the foll ...

  • 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.