strval() doesn't work for objects with __toString()
| Request #27125 | strval() doesn't work for objects with __toString() | ||||
|---|---|---|---|---|---|
| Submitted: | 2004-02-03 02:42 UTC | Modified: | 2004-03-14 17:51 UTC | ||
| From: | adam at trachtenberg dot com | Assigned: | |||
| Status: | Closed | Package: | Feature/Change Request | ||
| PHP Version: | 5CVS-2004-02-03 (dev) | OS: | * | ||
| Private report: | No | CVE-ID: | None | ||
[2004-02-03 02:42 UTC] 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
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2004-03-14 17:51 UTC] helly@php.net