src/AbstractStream.php
public static function fopen($resource = 'php://temp', $mode = 'w+b')
    {
        static::register();

        $context = stream_context_create(
            [static::PROTOCOL => ['resource' => $resource]]
        );
        set_error_handler(function () {
            throw new Exception('Failed to open stream.');
        });
        try {
            $fp = fopen(static::PROTOCOL . '://', $mode, false, $context);
        } catch (Exception $ex) {
            restore_error_handler();
            throw new InvalidArgumentException(sprintf(
                'Failed to create resource from "%s".',
                is_resource($resource) ? get_resource_type($resource)
                                       : gettype($resource)
            ), null, $ex);
        }
        restore_error_handler();

        return $fp;
    }
public static function fopen($resource = 'php://temp', $mode = 'w+b')
    {
        static::register();

        $context = stream_context_create(
            [static::PROTOCOL => ['resource' => $resource]]
        );
        set_error_handler(function () {
            throw new Exception('Failed to open stream.');
        });
        try {
            $fp = fopen(static::PROTOCOL . '://', $mode, false, $context);
        } catch (Exception $ex) {
            restore_error_handler();
            throw new InvalidArgumentException(sprintf(
                'Failed to create resource from "%s".',
                is_resource($resource) ? get_resource_type($resource)
                                       : gettype($resource)
            ), null, $ex);
        }
        restore_error_handler();

        return $fp;
    }
public static function fopen ( $ resource = 'php://temp' , $ mode = 'w+b' ) { static :: register ( ) ; $ context = stream_context_create ( [ static :: PROTOCOL => [ 'resource' => $ resource ] ] ) ; set_error_handler ( function ( ) { throw new Exception ( 'Failed to open stream.' ) ; } ) ; try { $ fp = fopen ( static :: PROTOCOL . '://' , $ mode , false , $ context ) ; } catch ( Exception $ ex ) { restore_error_handler ( ) ; throw new InvalidArgumentException ( sprintf ( 'Failed to create resource from "%s".' , is_resource ( $ resource ) ? get_resource_type ( $ resource ) : gettype ( $ resource ) ) , null , $ ex ) ; } restore_error_handler ( ) ; return $ fp ; }
Makes new resource from instance of current stream class.

@param string|resource $resource Optional; "php://temp" by default. The
resource wrapper reference as
"scheme://target" or resource to wrap
@param string          $mode     Optional; "w+b" by default. The type of
access to the stream if the access type
is not specified for a resource

@throws \InvalidArgumentException If failed to create resource from
received resource

@return resource New resource
Makes new resource from instance of current stream class .