As of PHP 5.1.4 (I have not tested it in later versions), the strval function does not attempt to invoke the __toString method when it encounters an object. This simple wrapper function will handle this circumstance for you:

<?

/** * Returns the string value of a variable * * This differs from strval in that it invokes __toString if an object is given * and the object has that method */function stringVal ($value){ // We use get_class_methods instead of method_exists to ensure that __toString is a public method if (is_object($value) && in_array("__toString", get_class_methods($value))) return strval($value->__toString()); else return strval($value);}