diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index d98c716fe1..bbd489a844 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -4100,6 +4100,8 @@ public function unsetExpression(Expr $expr): self $this->getType($expr->var)->unsetOffset($this->getType($expr->dim)), )->invalidateExpression( new FuncCall(new FullyQualified('count'), [new Arg($expr->var)]), + )->invalidateExpression( + new FuncCall(new FullyQualified('sizeof'), [new Arg($expr->var)]), ); } diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 4c236f85be..088619e961 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -702,6 +702,8 @@ public function dataFileAsserts(): iterable } yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6500.php'); + + yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6488.php'); } /** diff --git a/tests/PHPStan/Analyser/data/bug-6488.php b/tests/PHPStan/Analyser/data/bug-6488.php new file mode 100644 index 0000000000..7f66763d2d --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-6488.php @@ -0,0 +1,26 @@ + $value) { + if ($value % 2 === 0) { + unset($items[$key]); + } + } + + assertType('bool',sizeof($items) > 0); +}