note 73524 added to language.types.string
| From: | bryantatzionprogrammingdotcom at osu1 dot php dot net | Date: | Tue, 27 Feb 2007 20:16:27 +0000 |
| Subject: | note 73524 added to language.types.string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123934@lists.php.net to get a copy of this message | ||
As of (at least) PHP 5.2, you can no longer convert an object to a string unless it has a __toString
method. Converting an object without this method now gives the error:
PHP Catchable fatal error: Object of class <classname> could not be converted to string in
<file> on line <line>
Try this code to get the same results as before:
<?php
if (!is_object($value) || method_exists($value, '__toString')) {
$string = (string)$value;
} else {
$string = 'Object';
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 209.63.19.210
----
Manual Page -- http://www.php.net/manual/en/language.types.string.php
Edit -- https://master.php.net/note/edit/73524
Del: integrated -- https://master.php.net/note/delete/73524/integrated
Del: useless -- https://master.php.net/note/delete/73524/useless
Del: bad code -- https://master.php.net/note/delete/73524/bad+code
Del: spam -- https://master.php.net/note/delete/73524/spam
Del: non-english -- https://master.php.net/note/delete/73524/non-english
Del: in docs -- https://master.php.net/note/delete/73524/in+docs
Del: other reasons-- https://master.php.net/note/delete/73524
Reject -- https://master.php.net/note/reject/73524
Search -- https://master.php.net/manage/user-notes.php