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

From: Date: Wed, 28 Jul 2004 21:24:22 +0000
Subject: #26962 [Bgs]: __toString is not called during (string) cast and inside an expression
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-63705@lists.php.net to get a copy of this message
ID: 26962 Updated by: helly@php.net Reported By: alex_mailbox53 at yahoo dot com Status: Bogus Bug Type: Zend Engine 2 problem -Operating System: Gentoo Linux +Operating System: * -PHP Version: 5.0.0b3 (beta3) +PHP Version: 5.0.0 New Comment: Actually this is a PEAR problem. PEAR is not compatible with PHP 5. It is designed for PHP 4 only. Previous Comments: ------------------------------------------------------------------------ [2004-07-28 23:01:20] helly@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php For 5.0.x this is expected behavior. __toString() will only called automatically for echo and print constructs. Maybe we\'ll change that for 5.1. ------------------------------------------------------------------------ [2004-07-28 22:40:13] Maik_Heller at hotmail dot com problem still exists even with lates build (for win) ------------------------------------------------------------------------ [2004-01-24 23:59:56] sniper@php.net No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Open". Thank you. ------------------------------------------------------------------------ [2004-01-19 13:07:05] helly@php.net Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip ------------------------------------------------------------------------ [2004-01-19 05:01:43] alex_mailbox53 at yahoo dot com 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 this bug report at http://bugs.php.net/?id=26962&edit=1

« previous php.bugs (#63705) next »