php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39392 __toString back compatibility
Submitted: 2006-11-05 23:23 UTC Modified: 2006-11-06 14:26 UTC
From: marcos dot neves at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.0 OS: ANY
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: marcos dot neves at gmail dot com
New email:
PHP Version: OS:

 

 [2006-11-05 23:23 UTC] marcos dot neves at gmail dot com
Description:
------------
Object that do not implement __toString, now stop the script with "PHP Catchable fatal error:  Object of class {className} could not be converted to string in ..."

But for backward compatibility, if __toString is not  implemented, it should return the old object id value, or the name of class of the object for example.

I agree that nobody can rely on old ObjectId string, but there?s thousand scripts that stringfy data for logging,
like this:

function log($vars)
{
foreach($vars as $var) echo $var;
}

function test($a, $b)
{
    log(func_get_args());
}

Reproduce code:
---------------
class Foo { }
echo new Foo;

Expected result:
----------------
Old behavior of conversion from object to string

Actual result:
--------------
Catchable fatal error: Object of class Foo could not be converted to string in ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-06 14:26 UTC] 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

See upgrade info
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 07:01:33 2025 UTC