Skip to content

Commit 7b32a14

Browse files
qkdreyerbukka
authored andcommitted
Fix GH-15155: Keep stream context in filtered streams
Closes GH-15156
1 parent af8ef4c commit 7b32a14

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ PHP NEWS
3737
- Standard:
3838
. Unserializing the uppercase 'S' tag is now deprecated. (timwolla)
3939

40+
- Streams:
41+
. Implemented GH-15155 (Stream context is lost when custom stream wrapper is
42+
being filtered). (Quentin Dreyer)
43+
4044
01 Aug 2024, PHP 8.4.0alpha4
4145

4246
- GMP:

ext/standard/php_fopen_wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
352352
return NULL;
353353
}
354354

355-
if (!(stream = php_stream_open_wrapper(p + 10, mode, options, opened_path))) {
355+
if (!(stream = php_stream_open_wrapper_ex(p + 10, mode, options, opened_path, context))) {
356356
efree(pathdup);
357357
return NULL;
358358
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
GH-15155: Stream context is lost when custom stream wrapper is being filtered
3+
--FILE--
4+
<?php
5+
6+
class DummyWrapper
7+
{
8+
public $context;
9+
10+
public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool
11+
{
12+
$options = stream_context_get_options($this->context);
13+
var_dump($options['dummy']['foo']);
14+
return true;
15+
}
16+
17+
public function stream_stat()
18+
{
19+
}
20+
21+
public function stream_read()
22+
{
23+
}
24+
25+
public function stream_eof()
26+
{
27+
}
28+
}
29+
30+
$context = stream_context_create(['dummy' => ['foo' => 'bar']]);
31+
stream_wrapper_register('dummy', DummyWrapper::class);
32+
file_get_contents('dummy://foo', false, $context);
33+
@file_get_contents('php://filter/resource=dummy://foo', false, $context);
34+
?>
35+
--EXPECT--
36+
string(3) "bar"
37+
string(3) "bar"

0 commit comments

Comments
 (0)