Skip to content

Commit

Permalink
Merge pull request #6089 from orklah/getTypeResourceClosed
Browse files Browse the repository at this point in the history
Fix usage of gettype in a switch with closed resource
  • Loading branch information
weirdan committed Jul 14, 2021
2 parents 601c8ca + 0bd8b03 commit 09b0167
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Expand Up @@ -2381,7 +2381,15 @@ private static function getGettypeInequalityAssertions(
}
} else {
if ($var_name && $var_type) {
$if_types[$var_name] = [['!' . $var_type]];
if ($var_type === 'class@anonymous') {
$if_types[$var_name] = [['!=object']];
} elseif ($var_type === 'resource (closed)') {
$if_types[$var_name] = [['!closed-resource']];
} elseif (substr($var_type, 0, 10) === 'resource (') {
$if_types[$var_name] = [['!=resource']];
} else {
$if_types[$var_name] = [['!' . $var_type]];
}
}
}

Expand Down Expand Up @@ -3054,7 +3062,15 @@ private static function getGettypeEqualityAssertions(
}
} else {
if ($var_name && $var_type) {
$if_types[$var_name] = [[$var_type]];
if ($var_type === 'class@anonymous') {
$if_types[$var_name] = [['=object']];
} elseif ($var_type === 'resource (closed)') {
$if_types[$var_name] = [['closed-resource']];
} elseif (substr($var_type, 0, 10) === 'resource (') {
$if_types[$var_name] = [['=resource']];
} else {
$if_types[$var_name] = [[$var_type]];
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/FunctionCallTest.php
Expand Up @@ -792,6 +792,15 @@ function matchesTypes($maybe) : void {
if ($t === "object") {}
}',
],
'getTypeSwitchClosedResource' => [
'<?php
$data = "foo";
switch (gettype($data)) {
case "resource (closed)":
case "unknown type":
return "foo";
}',
],
'functionResolutionInNamespace' => [
'<?php
namespace Foo;
Expand Down

0 comments on commit 09b0167

Please sign in to comment.