note 73524 deleted from language.types.string by sobak

From: Date: Thu, 01 Dec 2016 17:29:33 +0000
Subject: note 73524 deleted from language.types.string by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207891@lists.php.net to get a copy of this message
Note Submitter: bryant at zionprogramming dot com ---- 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'; } ?>

« previous php.notes (#207891) next »