Use of OR in PHP statements _php tutorial

Source: Internet
Author: User
Often see this statement:
$file = fopen ($filename, R) or die ("Sorry, unable to open: $filename");
Or is understood here, because the data type is not differentiated in PHP, so the $file can be either int or bool, so the statement does not get an error. But the process may be some friends are not very clear.
In most languages, in a statement such as BOOL or bool, a value is no longer judged if the previous value is true. This is also the case, so if the fopen function executes correctly, it returns an int value greater than 0 (which is actually "true"), and the subsequent statement will not be executed. If the fopen function fails, it will return false, then it will determine if the subsequent expression is true.
The result is that after the die () is executed, no matter what is returned, the program has stopped executing, and the specified error message is displayed, and the purpose of debugging is achieved.
That's it. :)





http://www.bkjia.com/PHPjc/532514.html www.bkjia.com true http://www.bkjia.com/PHPjc/532514.html techarticle often see such statements: $file = fopen ($filename, R) or die ("Sorry, cannot open: $filename"), or is here to understand, because in PHP does not distinguish between data types, so ...

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