#26962 [NEW]: __toString is not called during (string) cast and inside an expression

From: Date: Mon, 19 Jan 2004 10:01:43 +0000
Subject: #26962 [NEW]: __toString is not called during (string) cast and inside an expression
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-53568@lists.php.net to get a copy of this message
From: alex_mailbox53 at yahoo dot com Operating system: Gentoo Linux PHP version: 5.0.0b3 (beta3) PHP Bug Type: Zend Engine 2 problem Bug description: __toString is not called during (string) cast and inside an expression Description: ------------ The ZEND_CHANGES defines that __toString method whould be called whenever object is casted to sting. But actually it is casted to string only during print (echo) operator. Even the example in ZEND_CHANGES does not work: class Foo { function __toString() { return "What ever"; } $obj = Foo; $str = (string) $obj; // call __toString() echo $obj; // call __toString() print $str will print the "Object" sring, not the "What ever". One more code example: class Integer { private $value; function __construct($val) { $this->value = $val; } function __toString() { return (string)($this->value); } } $i = new Integer(10); if (10 == $i) echo '10!!!! :-)'; "10!!! :-)" is not printed. Expected result: ---------------- When object is accessed in expressions it should be explicitly casted to sting nor vartype. -- Edit bug report at http://bugs.php.net/?id=26962&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26962&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26962&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=26962&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=26962&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=26962&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=26962&r=needscript Try newer version: http://bugs.php.net/fix.php?id=26962&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=26962&r=support Expected behavior: http://bugs.php.net/fix.php?id=26962&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=26962&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=26962&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=26962&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26962&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=26962&r=dst IIS Stability: http://bugs.php.net/fix.php?id=26962&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=26962&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=26962&r=float

« previous php.bugs (#53568) next »