#27125 [Opn->Csd]: strval() doesn't work for objects with __toString()
| From: | helly@php.net | Date: | Sun, 14 Mar 2004 22:51:27 +0000 |
| Subject: | #27125 [Opn->Csd]: strval() doesn't work for objects with __toString() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-56442@lists.php.net to get a copy of this message | ||
ID: 27125
Updated by: helly@php.net
Reported By: adam at trachtenberg dot com
-Status: Open
+Status: Closed
Bug Type: Feature/Change Request
Operating System: *
PHP Version: 5CVS-2004-02-03 (dev)
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2004-02-03 02:42:06] adam at trachtenberg dot com
Description:
------------
When strval() is passed an object with a __toString()
method, strval() should return the results of
__toString().
This makes strval() consistent with (string), which the
PHP manual agree to be the same thing:
"You can convert a value to a string using the (string)
cast, or the strval() function."
See also internals list discussion: http://www.mail-
archive.com/internals@lists.php.net/msg05832.html
Reproduce code:
---------------
class foo {
public function __toString() {
return "foo\n";
}
}
$foo = new foo;
print strval($foo);
Expected result:
----------------
foo
Actual result:
--------------
PHP Notice: Object of class foo could not be converted
to string in /Users/adam/Documents/php/php5/toString.php
on line 10
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27125&edit=1