Skip to content

Commit 3ec3b64

Browse files
Fix stream_bucket_make_writeable
1 parent 2808dfa commit 3ec3b64

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

resources/functionMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11699,7 +11699,7 @@
1169911699
'strcoll' => ['int', 'str1'=>'string', 'str2'=>'string'],
1170011700
'strcspn' => ['int', 'str'=>'string', 'mask'=>'string', 'start='=>'int', 'length='=>'int'],
1170111701
'stream_bucket_append' => ['void', 'brigade'=>'resource', 'bucket'=>'object'],
11702-
'stream_bucket_make_writeable' => ['object|null', 'brigade'=>'resource'],
11702+
'stream_bucket_make_writeable' => ['stdClass|null', 'brigade'=>'resource'],
1170311703
'stream_bucket_new' => ['object', 'stream'=>'resource', 'buffer'=>'string'],
1170411704
'stream_bucket_prepend' => ['void', 'brigade'=>'resource', 'bucket'=>'object'],
1170511705
'stream_context_create' => ['resource', 'options='=>'array', 'params='=>'array'],

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ public function dataFileAsserts(): iterable
899899
yield from $this->gatherAssertTypes(__DIR__ . '/data/unset-conditional-expressions.php');
900900
yield from $this->gatherAssertTypes(__DIR__ . '/data/conditional-types-inference.php');
901901
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7210.php');
902+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7341.php');
902903
}
903904

904905
/**
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Bug7341;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
final class CsvWriterTerminate extends \php_user_filter
8+
{
9+
/**
10+
* @param resource $in
11+
* @param resource $out
12+
* @param int $consumed
13+
* @param bool $closing
14+
*/
15+
public function filter($in, $out, &$consumed, $closing): int
16+
{
17+
while ($bucket = stream_bucket_make_writeable($in)) {
18+
assertType('stdClass', $bucket);
19+
20+
if (isset($this->params['terminate'])) {
21+
$bucket->data = preg_replace('/([^\r])\n/', '$1'.$this->params['terminate'], $bucket->data);
22+
}
23+
$consumed += $bucket->datalen;
24+
stream_bucket_append($out, $bucket);
25+
}
26+
27+
return \PSFS_PASS_ON;
28+
}
29+
}

0 commit comments

Comments
 (0)