Skip to content

Commit a86c34e

Browse files
Regression test
1 parent 7992a13 commit a86c34e

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
lines changed

resources/functionMap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,7 @@
23932393
'ffmpeg_movie::hasAudio' => ['bool'],
23942394
'ffmpeg_movie::hasVideo' => ['bool'],
23952395
'fgetc' => ['string|false', 'fp'=>'resource'],
2396-
'fgetcsv' => ['list<string>|array{0: null}|false|null', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
2396+
'fgetcsv' => ['non-empty-list<string>|array{0: null}|false|null', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
23972397
'fgets' => ['string|false', 'fp'=>'resource', 'length='=>'0|positive-int'],
23982398
'fgetss' => ['string|false', 'fp'=>'resource', 'length='=>'0|positive-int', 'allowable_tags='=>'string'],
23992399
'file' => ['list<string>|false', 'filename'=>'string', 'flags='=>'int-mask<FILE_USE_INCLUDE_PATH|FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES|FILE_NO_DEFAULT_CONTEXT>', 'context='=>'resource'],
@@ -9966,7 +9966,7 @@
99669966
'SplFileObject::fflush' => ['bool'],
99679967
'SplFileObject::fgetc' => ['string|false'],
99689968
// Do not believe https://www.php.net/manual/en/splfileobject.fgetcsv#refsect1-splfileobject.fgetcsv-returnvalues
9969-
'SplFileObject::fgetcsv' => ['list<string>|array{0: null}|false|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
9969+
'SplFileObject::fgetcsv' => ['non-empty-list<string>|array{0: null}|false|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
99709970
'SplFileObject::fgets' => ['string'],
99719971
'SplFileObject::fgetss' => ['string|false', 'allowable_tags='=>'string'],
99729972
'SplFileObject::flock' => ['bool', 'operation'=>'int-mask<LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB>', '&w_wouldblock='=>'0|1'],

resources/functionMap_php80delta.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +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'],
49+
'fgetcsv' => ['non-empty-list<string>|array{0: null}|false', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
5050
'filter_input' => ['mixed', 'type'=>'INPUT_GET|INPUT_POST|INPUT_COOKIE|INPUT_SERVER|INPUT_ENV', 'variable_name'=>'string', 'filter='=>'int', 'options='=>'array|int'],
5151
'filter_input_array' => ['array|false|null', 'type'=>'INPUT_GET|INPUT_POST|INPUT_COOKIE|INPUT_SERVER|INPUT_ENV', 'definition='=>'int|array', 'add_empty='=>'bool'],
5252
'floor' => ['float', 'number'=>'float'],

tests/PHPStan/Analyser/nsrt/fgetcsv-php7.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88

99
function test($resource): void
1010
{
11-
assertType('list<string|null>|false|null', fgetcsv($resource)); // nullable when invalid argument is given (https://3v4l.org/4WmR5#v7.4.30)
11+
assertType('non-empty-list<string|null>|false|null', fgetcsv($resource)); // nullable when invalid argument is given (https://3v4l.org/4WmR5#v7.4.30)
1212
}

tests/PHPStan/Analyser/nsrt/fgetcsv-php8.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88

99
function test($resource): void
1010
{
11-
assertType('list<string|null>|false', fgetcsv($resource));
11+
assertType('non-empty-list<string|null>|false', fgetcsv($resource));
1212
}

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,19 @@ public function testBug7684(): void
465465
$this->analyse([__DIR__ . '/data/bug-7684.php'], []);
466466
}
467467

468+
public function testBug4993(): void
469+
{
470+
$errors = [];
471+
if (PHP_VERSION_ID >= 80000) {
472+
$errors[] = [
473+
'Strict comparison using === between non-empty-list<string|null> and null will always evaluate to false.',
474+
11,
475+
];
476+
}
477+
478+
$this->analyse([__DIR__ . '/data/bug-4993.php'], $errors);
479+
}
480+
468481
public function testBug6181(): void
469482
{
470483
$this->analyse([__DIR__ . '/data/bug-6181.php'], []);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug4993;
4+
5+
$inputHandle = fopen('php://stdin','r');
6+
if ($inputHandle === false)
7+
{
8+
exit(1);
9+
}
10+
$row = fgetcsv( $inputHandle );
11+
if ( $row === false || $row === NULL )
12+
{
13+
exit(1);
14+
}

0 commit comments

Comments
 (0)