php.net |  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
Description:
------------
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:
---------------
<?php
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-31 13:07 UTC] johannes@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

.
 [2007-06-01 08:33 UTC] nikolai dot essel at maxworx dot com
The manual http://de3.php.net/manual/en/language.types.string.php says

[Quote]
Objects are always converted to the string "Object".
[Quote]
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC