|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41549 Object to String convert
Submitted: 2007-05-31 13:02 UTC Modified: 2007-06-01 08:33 UTC
From: nikolai dot essel at maxworx dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.2 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2007-05-31 13:02 UTC] nikolai dot essel at maxworx dot com
After updating from PHP 5.1.6 some scripts didn?t work.
Problem is the standard behavior from casting objects into strings without an explicit defined __toString() method

Reproduce code:
class test
	private $var = "test";
	public function __construct() {}

$object = new test();
echo $object;

Expected result:
Object id #1

Actual result:
Catchable fatal error: Object of class test could not be converted to string in C:\xampp\htdocs\classtest.php on line 9


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-31 13:07 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

 [2007-06-01 08:33 UTC] nikolai dot essel at maxworx dot com
The manual says

Objects are always converted to the string "Object".
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Sep 28 14:03:36 2021 UTC