From 3f20c2d1e220f1e5594ce24b79cb077f34d7b337 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sun, 5 Jan 2020 16:41:51 +0100 Subject: [PATCH] Fix Cannot unset offset 0 on $this when extending SimpleXMLElement --- src/Type/StaticType.php | 2 +- tests/PHPStan/Rules/Variables/UnsetRuleTest.php | 5 +++++ tests/PHPStan/Rules/Variables/data/bug-2752.php | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100755 tests/PHPStan/Rules/Variables/data/bug-2752.php diff --git a/src/Type/StaticType.php b/src/Type/StaticType.php index 20f60530b6..51a5906818 100644 --- a/src/Type/StaticType.php +++ b/src/Type/StaticType.php @@ -191,7 +191,7 @@ public function getIterableValueType(): Type public function isOffsetAccessible(): TrinaryLogic { - return $this->getStaticObjectType()->isInstanceOf(\ArrayAccess::class); + return $this->getStaticObjectType()->isOffsetAccessible(); } public function hasOffsetValueType(Type $offsetType): TrinaryLogic diff --git a/tests/PHPStan/Rules/Variables/UnsetRuleTest.php b/tests/PHPStan/Rules/Variables/UnsetRuleTest.php index aa7da81f74..c4ac52f589 100644 --- a/tests/PHPStan/Rules/Variables/UnsetRuleTest.php +++ b/tests/PHPStan/Rules/Variables/UnsetRuleTest.php @@ -48,4 +48,9 @@ public function testUnsetRule(): void ]); } + public function testBug2752(): void + { + $this->analyse([__DIR__ . '/data/bug-2752.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Variables/data/bug-2752.php b/tests/PHPStan/Rules/Variables/data/bug-2752.php new file mode 100755 index 0000000000..3c23f00ddb --- /dev/null +++ b/tests/PHPStan/Rules/Variables/data/bug-2752.php @@ -0,0 +1,13 @@ +