PHP bitwise operators don’t short circuit

A big difference between PHP’s bitwise operators (& and |) and logical operators (&& and ||) is that the bitwise operators don’t short circuit:
Consider the following code:

Bitwise Operators

$a = 0;
var_dump(true | $a++); // int(1)
var_dump(true & $a++); // int(1)

$a will now contain 2 because $a++ ran on both lines.

Logical Operators

$a = 0;
var_dump(true || $a++); // bool(true)
var_dump(true && $a++); // bool(false)

$a will now contain 1 because $a++ only ran the second time. The first time, the or statement short-circuited.
Related class: Introduction to PHP

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.