From 8c00e5506f8015623c05ff59eb9fb77ac2a132a8 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 28 Jul 2025 08:56:50 +0200 Subject: [PATCH 1/2] Add non regression test --- .../StrictComparisonOfDifferentTypesRuleTest.php | 13 +++++++++++++ tests/PHPStan/Rules/Comparison/data/bug-4993.php | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/PHPStan/Rules/Comparison/data/bug-4993.php diff --git a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php index a0efad16b4..e23ea2f67e 100644 --- a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php @@ -465,6 +465,19 @@ public function testBug7684(): void $this->analyse([__DIR__ . '/data/bug-7684.php'], []); } + public function testBug4993(): void + { + $errors = []; + if (PHP_VERSION_ID >= 80000) { + $errors[] = [ + 'Strict comparison using === between list and null will always evaluate to false.', + 11, + ]; + } + + $this->analyse([__DIR__ . '/data/bug-4993.php'], $errors); + } + public function testBug6181(): void { $this->analyse([__DIR__ . '/data/bug-6181.php'], []); diff --git a/tests/PHPStan/Rules/Comparison/data/bug-4993.php b/tests/PHPStan/Rules/Comparison/data/bug-4993.php new file mode 100644 index 0000000000..a479f32382 --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-4993.php @@ -0,0 +1,14 @@ + Date: Mon, 28 Jul 2025 09:06:26 +0200 Subject: [PATCH 2/2] Fix doc --- resources/functionMap.php | 4 ++-- resources/functionMap_php80delta.php | 2 +- tests/PHPStan/Analyser/nsrt/fgetcsv-php7.php | 2 +- tests/PHPStan/Analyser/nsrt/fgetcsv-php8.php | 2 +- .../Comparison/StrictComparisonOfDifferentTypesRuleTest.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/functionMap.php b/resources/functionMap.php index fade07b20c..6377df90f6 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -2932,7 +2932,7 @@ 'ffmpeg_movie::hasAudio' => ['bool'], 'ffmpeg_movie::hasVideo' => ['bool'], 'fgetc' => ['string|false', 'fp'=>'resource'], -'fgetcsv' => ['list|array{0: null}|false|null', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'], +'fgetcsv' => ['non-empty-list|array{0: null}|false|null', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'], 'fgets' => ['string|false', 'fp'=>'resource', 'length='=>'0|positive-int'], 'fgetss' => ['string|false', 'fp'=>'resource', 'length='=>'0|positive-int', 'allowable_tags='=>'string'], 'file' => ['list|false', 'filename'=>'string', 'flags='=>'int-mask', 'context='=>'resource'], @@ -11230,7 +11230,7 @@ 'SplFileObject::fflush' => ['bool'], 'SplFileObject::fgetc' => ['string|false'], // Do not believe https://www.php.net/manual/en/splfileobject.fgetcsv#refsect1-splfileobject.fgetcsv-returnvalues -'SplFileObject::fgetcsv' => ['list|array{0: null}|false|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'], +'SplFileObject::fgetcsv' => ['non-empty-list|array{0: null}|false|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'], 'SplFileObject::fgets' => ['string'], 'SplFileObject::fgetss' => ['string|false', 'allowable_tags='=>'string'], 'SplFileObject::flock' => ['bool', 'operation'=>'int-mask', '&w_wouldblock='=>'0|1'], diff --git a/resources/functionMap_php80delta.php b/resources/functionMap_php80delta.php index ebf9aa9a1a..2cd7afe20f 100644 --- a/resources/functionMap_php80delta.php +++ b/resources/functionMap_php80delta.php @@ -46,7 +46,7 @@ 'error_log' => ['bool', 'message'=>'string', 'message_type='=>'0|1|3|4', 'destination='=>'string', 'extra_headers='=>'string'], 'explode' => ['list', 'separator'=>'non-empty-string', 'str'=>'string', 'limit='=>'int'], 'fdiv' => ['float', 'dividend'=>'float', 'divisor'=>'float'], - 'fgetcsv' => ['list|array{0: null}|false', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'], + 'fgetcsv' => ['non-empty-list|array{0: null}|false', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'], 'filter_input' => ['mixed', 'type'=>'INPUT_GET|INPUT_POST|INPUT_COOKIE|INPUT_SERVER|INPUT_ENV', 'variable_name'=>'string', 'filter='=>'int', 'options='=>'array|int'], 'filter_input_array' => ['array|false|null', 'type'=>'INPUT_GET|INPUT_POST|INPUT_COOKIE|INPUT_SERVER|INPUT_ENV', 'definition='=>'int|array', 'add_empty='=>'bool'], 'floor' => ['float', 'number'=>'float'], diff --git a/tests/PHPStan/Analyser/nsrt/fgetcsv-php7.php b/tests/PHPStan/Analyser/nsrt/fgetcsv-php7.php index 8a38465040..be5f0eca91 100644 --- a/tests/PHPStan/Analyser/nsrt/fgetcsv-php7.php +++ b/tests/PHPStan/Analyser/nsrt/fgetcsv-php7.php @@ -8,5 +8,5 @@ function test($resource): void { - assertType('list|false|null', fgetcsv($resource)); // nullable when invalid argument is given (https://3v4l.org/4WmR5#v7.4.30) + assertType('non-empty-list|false|null', fgetcsv($resource)); // nullable when invalid argument is given (https://3v4l.org/4WmR5#v7.4.30) } diff --git a/tests/PHPStan/Analyser/nsrt/fgetcsv-php8.php b/tests/PHPStan/Analyser/nsrt/fgetcsv-php8.php index fccf29931c..0cf0882023 100644 --- a/tests/PHPStan/Analyser/nsrt/fgetcsv-php8.php +++ b/tests/PHPStan/Analyser/nsrt/fgetcsv-php8.php @@ -8,5 +8,5 @@ function test($resource): void { - assertType('list|false', fgetcsv($resource)); + assertType('non-empty-list|false', fgetcsv($resource)); } diff --git a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php index e23ea2f67e..30abde450f 100644 --- a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php @@ -470,7 +470,7 @@ public function testBug4993(): void $errors = []; if (PHP_VERSION_ID >= 80000) { $errors[] = [ - 'Strict comparison using === between list and null will always evaluate to false.', + 'Strict comparison using === between non-empty-list and null will always evaluate to false.', 11, ]; }