Hello again,

Am 20.03.2018 um 23:13 schrieb Dennis Birkholz:
> (I also appended both example files as I don't know how long snippets at
> 3v4l.org persist)

the list does not allow attachments, so inline. If this does not work,
3v4l must suffice.

Greets,
Dennis

<?php

\spl_autoload_register(function($class) {
    echo "Autoloader for '$class' called\n";
    class_alias(Test::class, $class);
    return true;
});

class Test
{
    static function blubb()
    {
        echo static::class, "\n";
    }
}

class MyStreamWrapper
{
    static $counter = 1;

    private $id;

    public function __construct()
    {
        $this->id = self::$counter++;
    }

    public function stream_open($path, $mode, $options, &$opened_path)
    {
        echo "({$this->id}) stream_open()\n";
        return true;
    }

    public function stream_write($data)
    {
        echo "({$this->id}) stream_write()\n";
        return \strlen($data);
    }

    public function stream_flush()
    {
        echo "({$this->id}) stream_flush()\n";

        if ($this->id === 1) {
            Lalala::blubb();
        } else {
            Foobar::blubb();
        }

        return true;
    }

    public function stream_close()
    {
        echo "({$this->id}) stream_close()\n";
        return true;
    }

    public function __destruct()
    {
        echo "({$this->id}) __destruct()\n";
    }
}

\stream_wrapper_register('test', MyStreamWrapper::class);

if (($handle = \fopen('test:///foobar', 'r+')) === false) {
    throw new \RuntimeException("Failed to open file");
}

if (\fwrite($handle, 'test') === false) {
    throw new \RuntimeException("Failed to write to file");
}

if (\fclose($handle) === false) {
    throw new \RuntimeException("Failed to close file");
}

if (($handle2 = \fopen('test:///blubb', 'r+')) === false) {
    throw new \RuntimeException("Failed to open file");
}

if (\fwrite($handle2, 'test') === false) {
    throw new \RuntimeException("Failed to write to file");
}


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to