| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2002-12-05 16:22 UTC] dparks at verinform dot com
 I cannot find any explanation of object copying or comparison in the PHP manual (or in the user comments). Even a note saying "don't expect comparison operators to work on objects" would by useful -- it would have saved me a couple of days of debugging and rewriting code. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 09:00:01 2025 UTC | 
Can you be more precise about what comparison operations you have in mind? Remember that PHP is not OOP, it is a language that supports OOP-style coding, so there is no inherent way of checking if 2 different instances of objects are of the same class w/ the same properties, or two variables pointing to the same object instance. The following code generates the expected result: function bool2str($bool) { if ($bool === false) { return 'FALSE'; } else { return 'TRUE'; } } class Foo { var $flag; function Foo($flag=true) { $this->flag = $flag; } } $o = new Foo(); $p = new Foo(false); $q = new Foo(); // this should be true echo bool2str($o == $q)."\n"; // this should be false echo bool2str($o != $q)."\n"; // this should be true echo bool2str($o === $q)."\n"; // this should be false echo bool2str($o == $p)."\n"; // this should be false echo bool2str($o === $p)."\n"; // this should be true echo bool2str($o != $p)."\n"; // this should be true echo bool2str($o !== $p)."\n";