|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-09-27 10:20 UTC] helly@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 00:00:02 2025 UTC |
Description: ------------ There are three different ways objects are converted to strings and they are inconsistent (depends on what function you are using). I think all object-to-string conversions should be done via __toString() if it is defined, even if the object is in quotes. Reproduce code: --------------- <?php class Message { function __toString() { return "Hello, World!\n"; } } $w = new Message; echo("$w"); echo("Message: " . $w); echo(substr($w,0)); echo($w); Expected result: ---------------- Hello, World! Message: Hello, World! Hello, World! Hello, World! Actual result: -------------- Object id #1 Message: Object id #1 Object Hello, World!