Boolean Assignment Operator

From: Date: Mon, 02 Feb 2009 12:49:59 +0000
Subject: Boolean Assignment Operator
Groups: php.general 
Request: Send a blank email to php-general+get-287527@lists.php.net to get a copy of this message
Hi, I'm fairly new to PHP, having migrated from the Java / C# world. I wrote some code similar to the following: $success = true; $success &= operation1(); $success &= operation2(); if ($success === true) { operation3(); // depends on 1 and 2 being successful } This didn't work as expected. After a bit of digging I found: * The &= operation isn't mentioned anywhere in the PHP documentation * The &= function seems to work as expected, however the following is observed... $success = true; $success &= true; print $success == true; // outputs 1 print $sucesss === true; // no output * The 'or' assignment operator |= causes no errors but doesn't work. Can any PHP gurus explain why the &= operator works at all, and why === seems to fail afterwards? Cheers, Gavin.

« previous php.general (#287527) next »