check if item can be converted to string?

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;
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)