Skip to content

Commit

Permalink
Fix Cannot unset offset 0 on $this when extending SimpleXMLElement
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 5, 2020
1 parent eeae2da commit 3f20c2d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Type/StaticType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Variables/UnsetRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ public function testUnsetRule(): void
]);
}

public function testBug2752(): void
{
$this->analyse([__DIR__ . '/data/bug-2752.php'], []);
}

}
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-2752.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Bug2572;

class Foo extends \SimpleXMLElement
{

public function doFoo()
{
unset($this[0]);
}

}

0 comments on commit 3f20c2d

Please sign in to comment.