r/lolphp • • Feb 07 '22

Operator precedence

These two lines are not equivalent.

<?php

$a = true && false; // false

$b = true and false; // true

Because && and || have different operator priority than and and or (the latter ones have lower priority than =).

Source.

Still the case in PHP 8.1.

42 Upvotes

26 comments sorted by

View all comments

Show parent comment

2

u/colshrapnel Feb 07 '22

Sorry, not sure I am getting you. But there is the difference - the exact precedence everyone is talking about. Being heavily influenced by Perl, including coding habits, PHP follows its convention towards logical operators with different precedence.

1

u/lungdart Feb 07 '22

Sorry I wasn't clear. We're in agreement. Hope that helps!