When should we use the php low precedence "or" operator instead of || operator?
Operator precedence in php - Stack Overflow
php - Operator precedence: multiple expressions with && and || - Stack Overflow
How to Write an Operator Precedence Parser in PHP
Could be useful, thanks.
Im using PHP_Parser to create a basic VM for PHP (in the hope of some basic automated vulnerability detection)
You might like to look at the Spl classes though (Php 5.3+).
http://php.net/manual/en/spl.datastructures.php
There are native stack and queue classes, so they dont have to be emulated using arrays anymore
More on reddit.comVideos
The book says that in below case, we can only use the or operator and not || operator, but I don't understand why:
mysql_select_db($database) or die("Unable to select database");Can someone please explain why you can't use || in above example?
&& depends of the evaluation of the right expression when left one is true, || doesn't. You could rewrite it to:
if(
$users == 'all' ||
($_POST['user'] == 1 && $users == 'admins') ||
($_POST['user'] == 0 && $users == 'mods')
)
And it'll be the same.
With no parenthesis, PHP will evaluate each expression from left to right, using PHP's operator precedence along the way. However, as in any logical check, throwing AND into the mix can make things confusing and a lot harder to read.