ID: 30098
Comment by: robertd at onid dot orst dot edu
Reported By: brandon at osuosl dot org
Status: Open
Bug Type: Zend Engine 2 problem
Operating System: Debian Unstable
PHP Version: 5.0.1
New Comment:
Not sure if this is needed information, but:
the automatic __toString will also fail on member objects of $this.
For example:
-------------------------
$class = new MyClass();
echo $class->something();
class MyClass {
private $obj;
public function something() {
$this->obj = new SomeObject();
$str = (string) $this->obj;
return $str;
}
}
class SomeObject {
public function __toString() {
$str = 'Some string';
return $str;
}
}
-------------------------
Echoes "Object id #2"
Previous Comments:
------------------------------------------------------------------------
[2004-09-15 20:18:13] brandon at osuosl dot org
Description:
------------
The automatic __toString method does not work on $this.
I don't know if it should or not but it seems like it should be ok to
do this.
Thanks.
http://dev2.osuosl.org/~philips/tostring/index.php
http://dev2.osuosl.org/~philips/tostring/index.phps
Reproduce code:
---------------
class Foo {
function __toString() {
return "What ever";
}
function ihatemylife() {
$str = (string) $this;
return $str;
}
}
$obj = new Foo;
$str = (string) $obj; // call __toString()
echo $obj; // call __toString()
echo "<br />";
echo $obj->ihatemylife();
echo "<br />";
phpinfo();
Expected result:
----------------
This line should return "What ever"
echo $obj->ihatemylife();
Actual result:
--------------
Object id #1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30098&edit=1