#20266 [Opn->Bgs]: Logical OR fails if results of two methods are evaluated

From: Date: Tue, 05 Nov 2002 20:29:42 +0000
Subject: #20266 [Opn->Bgs]: Logical OR fails if results of two methods are evaluated
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-24142@lists.php.net to get a copy of this message
ID: 20266 Updated by: moriyoshi@php.net Reported By: tim@afeindustries.com -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: W2K PHP Version: 4.2.2 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php The right portion is never evaluated by an || operator when the left portion gives true. This needs to be written as following $result1 = $this->logicalOne(); $result2 = $this->logicalTwo() ) if ($result1 || $result2) { ... } Previous Comments: ------------------------------------------------------------------------ [2002-11-05 14:08:02] tim@afeindustries.com Dear PHP TEAM, Thanks for such a great product. This baby makes our day, every day! We have recently found one strange thing. When we need to LOGICALLY-OR the results of two boolean methods of a class, PHP bypasses execution of the second method (if first method returns TRUE). Since the second method is never executed we can not get the desired result. Please, take a look at the body of the CONSTRUCTOR below: //---- BEGINNING OF FILE 'sample.php' class CSample { function CSample() { echo 'Some news are here:<br>'; // Below, PHP actually doesn't // runs $this->logicalTwo() if( $this->logicalOne() || $this->logicalTwo() ) { echo '<br>What more do you want?'; // .. } } // SERVICE METHODS function logicalOne() { //.. echo ' GOT CAR '; return true; } function logicalTwo() { //.. echo ' GOT MONEY '; return true; } }; // Instantiating the class $object1 = new CSample(); //---- END OF FILE 'sample.php' OUTPUT: Some news are here: GOT CAR What more do you want? See, there is no 'GOT MONEY' text printed. Please advise. Is this the correct behavior or something is not working right. Many thanks, Tim B. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=20266&edit=1

« previous php.bugs (#24142) next »