#34286 [NEW]: __toString() behavior is inconsistent

From: Date: Sun, 28 Aug 2005 08:59:58 +0000
Subject: #34286 [NEW]: __toString() behavior is inconsistent
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-84082@lists.php.net to get a copy of this message
From: alek at zvuk dot net Operating system: Any PHP version: 5CVS-2005-08-28 (snap) PHP Bug Type: Scripting Engine problem Bug description: __toString() behavior is inconsistent 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! -- Edit bug report at http://bugs.php.net/?id=34286&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34286&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34286&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34286&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=34286&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=34286&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=34286&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=34286&r=needscript Try newer version: http://bugs.php.net/fix.php?id=34286&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=34286&r=support Expected behavior: http://bugs.php.net/fix.php?id=34286&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=34286&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=34286&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=34286&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34286&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=34286&r=dst IIS Stability: http://bugs.php.net/fix.php?id=34286&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=34286&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=34286&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=34286&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=34286&r=mysqlcfg

« previous php.bugs (#84082) next »