Date: 12/05/02
- Next message: leon <email protected>: "[PHP-DOC] #20850 [NEW]: str_shuffle needs documentation"
- Previous message: sniper <email protected>: "[PHP-DOC] #20836 [Opn]: sybase_fetch_assoc & mssql_fetch_assoc missing"
- In reply to: dparks <email protected>: "[PHP-DOC] #20842 [NEW]: No explanation of object comparison and copying"
- Next in thread: goba <email protected>: "[PHP-DOC] #20842 [Opn]: No explanation of object comparison and copying"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
ID: 20842
User updated by: dparks <email protected>
Reported By: dparks <email protected>
-Status: Feedback
+Status: Open
Bug Type: Documentation problem
Operating System: Any
PHP Version: 4.2.3
New Comment:
Argh!! Apparently, PHP evaluates
$this->val = val;
without error, treating val like 'val'. I can't find this documented in
the manual.
The code posted near the end of the bug at
http://bugs.php.net/bug.php?id=20681 (look for [28 Nov 2:02pm]
moriyoshi <email protected>) contains an error like this, which was not noticed
by 4 people. Because of this, the code returns true for all
comparisons.
The behavior you describe is what I expected. Sorry about the mixup.
It would still be nice to have an explanation about how copies
(assignment) are done on objects -- is this a deep value copy? How are
references handled?
Also, it would be nice if the comparison operator page explained how
recursion is handled.
Previous Comments:
------------------------------------------------------------------------
[2002-12-05 19:11:48] jmcastagnetto <email protected>
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";
------------------------------------------------------------------------
[2002-12-05 16:22:03] dparks <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
- Next message: leon <email protected>: "[PHP-DOC] #20850 [NEW]: str_shuffle needs documentation"
- Previous message: sniper <email protected>: "[PHP-DOC] #20836 [Opn]: sybase_fetch_assoc & mssql_fetch_assoc missing"
- In reply to: dparks <email protected>: "[PHP-DOC] #20842 [NEW]: No explanation of object comparison and copying"
- Next in thread: goba <email protected>: "[PHP-DOC] #20842 [Opn]: No explanation of object comparison and copying"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

