Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "or" in php mean? [duplicate]

Tags:

syntax

php

Possible Duplicate:
PHP - and / or keywords

I saw several bits of PHP code using or in a way I was unfamiliar with. For example:

fopen($site,"r") or die("Unable to connect to $site");

Is this equal to this ||?

Why would you use this instead of a try catch block? What will cause the program run the or die()?

like image 769
Tattat Avatar asked Apr 09 '26 18:04

Tattat


2 Answers

It is for the most part, but...

The reason for the two different variations of "and" and "or" operators is that they operate at different precedences.

See http://php.net/manual/en/language.operators.logical.php

like image 155
Daniel A. White Avatar answered Apr 12 '26 21:04

Daniel A. White


or is equal to || except that || has a higher presedense than or.

Reference:

http://www.php.net/manual/en/language.operators.precedence.php

like image 42
Mike Lewis Avatar answered Apr 12 '26 22:04

Mike Lewis