I am writing a debug method.
What I have is
if(is_xxx($item)){ //echo output info for type }
what I want to do at the end is
if(can_be_string($item)) echo $item;
Is there a can_be_string
type function?
Ok, edited, with incorporating Michiel Pater's suggestion (who's answer is gone now) ans @eisberg's suggestions. settype
will return true
with objects no matter what, as it seems.
if( ( !is_array( $item ) ) && ( ( !is_object( $item ) && settype( $item, 'string' ) !== false ) || ( is_object( $item ) && method_exists( $item, '__toString' ) ) ) ) { echo $item; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With