Home > Backend Development > PHP Tutorial > Usage of or in PHP statements_PHP tutorial

Usage of or in PHP statements_PHP tutorial

WBOY
Release: 2016-07-13 17:21:08
Original
1009 people have browsed it

I often see statements like this:
$file = fopen($filename, r) or die("Sorry, cannot open: $filename");
or is understood like this here, because in PHP does not distinguish between data types, so $file can be either int or bool, so such a statement will not report an error. But some friends may not understand the processing process.
In fact, in most languages, in statements like bool or bool, if the previous value is true, the next value will not be judged. The same is true here, so if the fopen function is executed correctly, it will return an int value greater than 0 (which is actually "true"), and the subsequent statements will not be executed. If the fopen function fails to execute, it will return false, and then it will be judged whether the following expression is true.
After executing die(), no matter what is returned, the program has stopped executing and the specified error message is displayed, thus achieving the purpose of debugging.
That’s it. :)





www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532514.htmlTechArticleI often see statements like this: $file = fopen($filename, r) or die("Sorry, can't Open: $filename"); or is understood here, because data types are not distinguished in PHP, so...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template