You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?phpfunctioncloseFile($file)
{
fclose($file);
}
$file = fopen(__FILE__, 'r');
if (false === $file) {
thrownew \RuntimeException('foo');
}
echo"\n".gettype($file);
closeFile($file);
echo"\n".gettype($file);
if (!is_resource($file)) {
echo"\nNot a resource";
}
output:
$ php var/tmp/psalm/test2.php
resource
resource (closed)
Not a resource
ERROR: TypeDoesNotContainType - 20:6 - Found a contradiction when evaluating $file and trying to reconcile type 'resource' to !resource
I think this error is not correct. When running the code the type of $file becomes resource when opened and gets changed to resource (closed) because of the fclose call on it. As such the !is_resource check seems valid.
The example code is over simplified, a production sample I've got is when guzzle closes the file handle on successful download.
The text was updated successfully, but these errors were encountered:
ERROR: RedundantCondition - var/tmp/psalm/test2.php:21:5 - Found a redundant condition when evaluating $file and trying to reconcile type 'resource' to resource
if (is_resource($file)) {
Hi all,
https://psalm.dev/r/1944680e7d
output:
I think this
error
is not correct. When running the code the type of$file
becomesresource
when opened and gets changed toresource (closed)
because of thefclose
call on it. As such the!is_resource
check seems valid.The example code is over simplified, a production sample I've got is when guzzle closes the file handle on successful download.
The text was updated successfully, but these errors were encountered: