ID:               33270
 Updated by:       [EMAIL PROTECTED]
 Reported By:      Jesselnz at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Strings related
 Operating System: All
 PHP Version:      5.0.3
 New Comment:

what he said


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

[2005-06-08 15:07:03] nick dot telford at gmail dot com

This is not a bug, as stated in the docs (www.php.net/oop5)
__toString() will only be automatically called if directly combined
with echo/print with NOTHING BEFORE THE OBJECT! (not even a cast).

echo (string) $obj;

would print Object, since __toString() is not invoked.

__toString()'s implementation is going to be changed/removed completely
in PHP5.1

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

[2005-06-08 03:42:19] Jesselnz at gmail dot com

Description:
------------
Typecasting an object with a __toString() function returns the string
'Object' and doesn't run __toString().

Reproduce code:
---------------
<?php
class Foobar
{
.....public function __toString ()
.....{
..........echo '__toString() was run.', "\n";
..........return ('./includes/foobar.php');
.....}
}

$foobar = new Foobar ();
require ((string) $foobar);
?>

Expected result:
----------------
__toString() was run.

require ('./includes/foobar.php');

Actual result:
--------------
require ('Object');


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


-- 
Edit this bug report at http://bugs.php.net/?id=33270&edit=1

Reply via email to