ID:               20842
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Feedback
 Bug Type:         Documentation problem
 Operating System: Any
 PHP Version:      4.2.3
 New Comment:

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";





Previous Comments:
------------------------------------------------------------------------

[2002-12-05 16:22:03] [EMAIL PROTECTED]

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.

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=20842&edit=1


-- 
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to