Usage of or in PHP statements

Source: Internet
Author: User
We often see this statement: $ file = fopen ($ filename, 'r') ordie ("negative loss, cannot open: $ filename"); or here we know this, because the data types are not differentiated in PHP, $ file can be int or bool. Therefore, such statements do not often see such statements:
$ File = fopen ($ filename, 'r') or die ('negative Referer, cannot open: $ filename ');
Or this is the case here. because the data type is not distinguished in PHP, $ file can be either int or bool, so such a statement will not report an error. However, some friends may not understand the process.
In most languages, in statements such as bool or bool, if the previous value is true, the latter value will not be determined. So if the fopen function is executed accurately, an int value greater than 0 will be returned (this is actually "true"), and the subsequent statements will not be executed. If the fopen function fails to be executed, false is returned, and the following expression is determined to be true.
After the result is executed by die (), no matter what is returned, the program has been executed and the specified error information is displayed, thus achieving the debugging goal.
That's it. :)

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.