ID:               30098
 Updated by:       [EMAIL PROTECTED]
 Reported By:      brandon at osuosl dot org
-Status:           Open
+Status:           Bogus
 Bug Type:         Zend Engine 2 problem
 Operating System: Debian Unstable
 PHP Version:      5.0.1
 New Comment:

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

__toString() is never called automatically.

We had to drop this magic right before 5.0 was released and may be able
to reintroduce it to 5.1.


Previous Comments:
------------------------------------------------------------------------

[2004-09-15 20:32:44] robertd at onid dot orst dot edu

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"

------------------------------------------------------------------------

[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

Reply via email to