-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
phpstan/phpstan-src
#2276Labels
Milestone
Description
Bug report
"Method x() should return array but returns false." error is reported when return array_combine($a, $b); although the call to array_combine never returns false.
According to the docs https://www.php.net/manual/en/function.array-combine.php:
As of PHP 8.0.0, a ValueError is thrown if the number of elements in keys and values does not match. Prior to PHP 8.0.0, a E_WARNING was emitted instead.
Executing this in PHP generates a warning but does not return false - https://onlinephp.io/c/4f929.
Code snippet that reproduces the problem
<?php declare(strict_types = 1);
class HelloWorld
{
/**
* @return string[]
*/
public function getX(): array
{
$a = array('green', 'red', 'yellow', 'y');
$b = array('avocado', 'apple', 'banana');
return array_combine($a, $b);
}
}
https://phpstan.org/r/4e381b5b-88e6-4e6a-8e68-9232819c74d1
Expected output
No error should be reported.
Reactions are currently unavailable