public static InputStream getInputStream(Environment env, Memory arg){
        try {
            if (arg.instanceOf(FileObject.class)){
                return new FileInputStream(arg.toObject(FileObject.class).file);
            } else if (arg.instanceOf(Stream.class)){
                if (arg.instanceOf(ResourceStream.class)) {
                    return arg.toObject(ResourceStream.class).getInputStream();
                }

                return new StreamInputStream(env, arg.toObject(Stream.class));
            } else {
                StreamInputStream inputStream = new StreamInputStream(env, Stream.create(env, arg.toString(), "r"));
                inputStream.autoClose = true;
                return inputStream;
            }
        } catch (IOException e){
            env.exception(WrapIOException.class, e.getMessage());
        } catch (Throwable throwable) {
            env.forwardThrow(throwable);
        }

        return null;
    }
@param arg - File path or Stream object
@return
jphp-runtime/src/php/runtime/ext/core/classes/stream/Stream.java