|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-05-26 01:49 UTC] doublecompile at gmail dot com
Description:
------------
Attempting to stringify (casting, strval, echo) an instantiated class without a __toString() method results in the following error:
Catchable fatal error: Object of class test could not be converted to string in...
Built using php5.2-200605252230 Snap with the following config statement:
'./configure' '--with-mysql=/usr/local/php5/ext/mysql' '--with-pdo' '--with-pdo-mysql' '--with-apxs2=/usr/bin/apxs2' '--with-zlib' '--enable-bcmath' '--enable-calendar' '--with-gd=/usr' '--with-jpeg-dir=/usr/include' '--with-zlib-dir=/usr/include' '--with-png-dir=/usr/include' '--with-xpm-dir=/usr/include' '--with-freetype-dir=/usr/include' '--with-ldap' '--with-mcrypt' '--with-mhash' '--with-bz2' '--with-curl' '--enable-ftp' '--with-openssl' '--with-mysqli' '--enable-exif' '--enable-wddx' '--with-xsl' '--enable-sockets' '--enable-soap' '--with-pgsql=/usr/lib/postgresql' '--with-pdo-pgsql=/usr/lib/postgresql' '--with-sqlite' '--with-pdo-sqlite' '--with-ibm-db2=/home/db2inst1/sqllib' '--with-pdo-odbc=ibm-db2,/home/db2inst1/sqllib' '--enable-mbstring' '--with-gettext'
Reproduce code:
---------------
class test { }
$test = new test();
// any of the following would produce the error
$value = (string)$test;
$value = strval($test);
echo $test;
Expected result:
----------------
$value to be set to "Object #1"
or the echo to output "Object #1"
Actual result:
--------------
Catchable fatal error: Object of class test could not be converted to string in...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 18:00:01 2025 UTC |
Try this on for size: <?php class test { public $value; } $test = new test(); $test->value = "1234"; $test2 = new test(); $test->value = "5678"; $test3 = new test(); $test->value = "7890"; $example = array( $test, $test2, $test3, $test3 ); $filtered = array_unique( $example ); ?> Outputs: Catchable fatal error: Object of class test could not be converted to string in ...