__toString() with cast is broken in php5 RC1
| From: | David Giffin | Date: | Thu, 01 Apr 2004 23:13:28 +0000 |
| Subject: | __toString() with cast is broken in php5 RC1 | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-8880@lists.php.net to get a copy of this message | ||
Hi There,
I just got a chance tp update to PHP5 RC1 and noticed that some things
have changed for the __toString method. It seems that it it only getting
called when the object is printed or echo. Casting the object to a string
returns the Object #. Here is an example:
---- The Script:
<?php
class obj
{
function __toString()
{
return "yo!!\n";
}
}
$obj = new obj();
print_r($obj);
$test = (string) $obj;
print $test;
print $obj;
?>
----- Produces:
obj Object
(
)
Object id #1yo!!
Thanks,
David