Skip to content

Add non regression test for 4993 #4182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2932,7 +2932,7 @@
'ffmpeg_movie::hasAudio' => ['bool'],
'ffmpeg_movie::hasVideo' => ['bool'],
'fgetc' => ['string|false', 'fp'=>'resource'],
'fgetcsv' => ['list<string>|array{0: null}|false|null', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
'fgetcsv' => ['non-empty-list<string>|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<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'],
Expand Down Expand Up @@ -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<string>|array{0: null}|false|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
'SplFileObject::fgetcsv' => ['non-empty-list<string>|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<LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB>', '&w_wouldblock='=>'0|1'],
Expand Down
2 changes: 1 addition & 1 deletion resources/functionMap_php80delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'error_log' => ['bool', 'message'=>'string', 'message_type='=>'0|1|3|4', 'destination='=>'string', 'extra_headers='=>'string'],
'explode' => ['list<string>', 'separator'=>'non-empty-string', 'str'=>'string', 'limit='=>'int'],
'fdiv' => ['float', 'dividend'=>'float', 'divisor'=>'float'],
'fgetcsv' => ['list<string>|array{0: null}|false', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
'fgetcsv' => ['non-empty-list<string>|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'],
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/fgetcsv-php7.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

function test($resource): void
{
assertType('list<string|null>|false|null', fgetcsv($resource)); // nullable when invalid argument is given (https://3v4l.org/4WmR5#v7.4.30)
assertType('non-empty-list<string|null>|false|null', fgetcsv($resource)); // nullable when invalid argument is given (https://3v4l.org/4WmR5#v7.4.30)
}
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/fgetcsv-php8.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

function test($resource): void
{
assertType('list<string|null>|false', fgetcsv($resource));
assertType('non-empty-list<string|null>|false', fgetcsv($resource));
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 non-empty-list<string|null> 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'], []);
Expand Down
14 changes: 14 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-4993.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types = 1);

namespace Bug4993;

$inputHandle = fopen('php://stdin','r');
if ($inputHandle === false)
{
exit(1);
}
$row = fgetcsv( $inputHandle );
if ( $row === false || $row === NULL )
{
exit(1);
}
Loading