azure-storage-common/src/Common/Internal/Serialization/MessageSerializer.php
public static function objectSerialize($targetObject)
    {
        //if the object is of exception type, serialize it using the methods
        //without checking the methods.
        if ($targetObject instanceof RequestException) {
            return self::serializeRequestException($targetObject);
        } elseif ($targetObject instanceof \Exception) {
            return self::serializeException($targetObject);
        }

        Validate::methodExists($targetObject, 'getHeaders', 'targetObject');
        Validate::methodExists($targetObject, 'getProtocolVersion', 'targetObject');

        // Serialize according to the implemented method.
        if (method_exists($targetObject, 'getUri') &&
            method_exists($targetObject, 'getMethod')) {
            return self::serializeRequest($targetObject);
        } elseif (method_exists($targetObject, 'getStatusCode') &&
                   method_exists($targetObject, 'getReasonPhrase')) {
            return self::serializeResponse($targetObject);
        } else {
            throw new \InvalidArgumentException(
                Resources::INVALID_MESSAGE_OBJECT_TO_SERIALIZE
            );
        }
    }
public static function objectSerialize($targetObject)
    {
        //if the object is of exception type, serialize it using the methods
        //without checking the methods.
        if ($targetObject instanceof RequestException) {
            return self::serializeRequestException($targetObject);
        } elseif ($targetObject instanceof \Exception) {
            return self::serializeException($targetObject);
        }

        Validate::methodExists($targetObject, 'getHeaders', 'targetObject');
        Validate::methodExists($targetObject, 'getProtocolVersion', 'targetObject');

        // Serialize according to the implemented method.
        if (method_exists($targetObject, 'getUri') &&
            method_exists($targetObject, 'getMethod')) {
            return self::serializeRequest($targetObject);
        } elseif (method_exists($targetObject, 'getStatusCode') &&
                   method_exists($targetObject, 'getReasonPhrase')) {
            return self::serializeResponse($targetObject);
        } else {
            throw new \InvalidArgumentException(
                Resources::INVALID_MESSAGE_OBJECT_TO_SERIALIZE
            );
        }
    }
Serialize a message to a string. The message object must be either a type
of \Exception, or have following methods implemented.
getHeaders()
getProtocolVersion()
(getUri() && getMethod()) || (getStatusCode() && getReasonPhrase())

@param object $message The message to be serialized.

@return string