When PHP detects if a variable is set, can empty () Replace isset ()? _php Tutorials

Source: Internet
Author: User
Let's go over the empty and isset empty-check if a variable is empty "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties will be considered empty, and if VAR is null, returns TRUE if the isset-detects whether the variable is set, and is not NULL. That is: The variable is not set and returns false; variable is null, return false the PHP manual explains the comparison clearly, but if a variable is not set, what result does empty return? [PHP] Var_dump (Empty ($undefined)); Var_dump (Empty ($undefined)); The result is: BOOL (true) is visible and empty can also be used to detect whether the variable is set. So should we use empty instead of isset? I think if only to judge a variable exists, then the use of isset, because the meaning of isset is clear, is to do this use, but also conducive to the reading of the code. When it is necessary to determine the existence of variables, and the judgment variable is not 0, ", empty array, etc., you can use [PHP] if (!empty ($var)) instead of if (Isset ($var) &&!empty ($var)) if (!empty ($var)) Instead of if (Isset ($var) &&!empty ($var)) when you want to determine whether a variable is NULL, you must not use Isset. Here are some more things: Isset and empty performance? In fact, isset and empty performance are very good, the difference is not small. Also say that they are all statements, not functions, want to look specifically at this aspect of the content, you can see the bird brother of this article "the difference between Isset and is_null" statement can not be called by the variable function, in addition, in isset and empty can not accept the function of the return value as a parameter, For example, this is not possible [PHP] Empty (intval (' 3 ')); Fatal Error:can ' t use function return value in write context empty (Intval (' 3 ')),//fatal Error:can ' t use function retur n value in write context However, the current release of PHP5.5 supports this feature, which is the ability to use arbitrary expressions in empty: [PHP] FuNction Always_false () {return false;} if (Empty (Always_false ())) {echo "This would be printed.\n";} function Always_fal Se () {return false;} if (Empty (Always_false ())) {echo "This would be printed.\n";} Will output: This would be printed.

http://www.bkjia.com/PHPjc/477203.html www.bkjia.com true http://www.bkjia.com/PHPjc/477203.html techarticle let's go over the empty and isset. Empty checks if a variable is empty, 0, 0, NULL, FALSE, Array (), Var $var, and objects that do not have any properties will be considered empty, such as ...

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