[php-src] Issue #15155: Stream context is lost when custom stream wrapper is being filtered
| From: | qkdreyer | Date: | Mon, 29 Jul 2024 15:32:52 +0000 |
| Subject: | [php-src] Issue #15155: Stream context is lost when custom stream wrapper is being filtered | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247393@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/15155
Author: qkdreyer
### Description
The following code:
```php
<?php
class DummyWrapper
{
public $context;
public static function register(): void
{
\stream_wrapper_register('dummy', self::class);
}
public function stream_open(string $path, string $mode, int $options, ?string
&$opened_path): bool
{
$options = \stream_context_get_options($this->context);
var_dump($options['dummy']['foo']);
return true;
}
public function stream_stat()
{
}
public function stream_read()
{
}
public function stream_eof()
{
}
}
DummyWrapper::register();
\file_get_contents('dummy://foo', false, \stream_context_create(['dummy' =>
['foo' => 'bar']]));
\file_get_contents('php://filter/resource=dummy://foo', false,
\stream_context_create(['dummy' => ['foo' => 'bar']]));
```
Resulted in this output:
```
string(3) "bar"
Fatal error: Uncaught TypeError: stream_context_get_options(): Argument #1 ($stream_or_context) must
be of type resource, null given in /in/hlqFE:14
Stack trace:
#0 /in/hlqFE(14): stream_context_get_options(NULL)
#1 [internal function]: DummyWrapper->stream_open('dummy://foo', 'rb', 0,
NULL)
#2 /in/hlqFE(35): file_get_contents('php://filter/re...', false, Resource id #7)
#3 {main}
thrown in /in/hlqFE on line 14
```
But I expected this output instead:
```
string(3) "bar"
string(3) "bar"
```
### PHP Version
PHP 8.3.9
### Operating System
_No response_