|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20266 Logical OR fails if results of two methods are evaluated
Submitted: 2002-11-05 14:08 UTC Modified: 2002-11-05 14:32 UTC
From: tim at afeindustries dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.2.2 OS: W2K
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
44 - 17 = ?
Subscribe to this entry?

 [2002-11-05 14:08 UTC] tim at afeindustries dot com
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?';
            // ..
    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'


Some news are here:
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-05 14:29 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

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) {
 [2002-11-05 14:32 UTC] tim at afeindustries dot com
Thanks for clarifications,
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 29 20:01:30 2024 UTC