Skip to content

Commit fbcad41

Browse files
authored
Fix fgetcsv return type; never returns null
1 parent 28dfac8 commit fbcad41

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Diff for: resources/functionMap_php80delta.php

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
'error_log' => ['bool', 'message'=>'string', 'message_type='=>'0|1|3|4', 'destination='=>'string', 'extra_headers='=>'string'],
4747
'explode' => ['list<string>', 'separator'=>'non-empty-string', 'str'=>'string', 'limit='=>'int'],
4848
'fdiv' => ['float', 'dividend'=>'float', 'divisor'=>'float'],
49+
'fgetcsv' => ['list<string>|array{0: null}|false', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
4950
'filter_input' => ['mixed', 'type'=>'INPUT_GET|INPUT_POST|INPUT_COOKIE|INPUT_SERVER|INPUT_ENV', 'variable_name'=>'string', 'filter='=>'int', 'options='=>'array|int'],
5051
'filter_input_array' => ['array|false|null', 'type'=>'INPUT_GET|INPUT_POST|INPUT_COOKIE|INPUT_SERVER|INPUT_ENV', 'definition='=>'int|array', 'add_empty='=>'bool'],
5152
'floor' => ['float', 'number'=>'float'],

Diff for: tests/PHPStan/Analyser/nsrt/fgetcsv-php7.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php // lint < 8.0
2+
3+
declare(strict_types = 1);
4+
5+
namespace TestFGetCsvPhp7;
6+
7+
use function PHPStan\Testing\assertType;
8+
9+
function test($resource): void
10+
{
11+
assertType('list<string|null>|false|null', fgetcsv($resource)); // nullable when invalid argument is given (https://3v4l.org/4WmR5#v7.4.30)
12+
}

Diff for: tests/PHPStan/Analyser/nsrt/fgetcsv-php8.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php // lint >= 8.0
2+
3+
declare(strict_types = 1);
4+
5+
namespace TestFGetCsvPhp8;
6+
7+
use function PHPStan\Testing\assertType;
8+
9+
function test($resource): void
10+
{
11+
assertType('list<string|null>|false', fgetcsv($resource));
12+
}

0 commit comments

Comments
 (0)