diff --git a/stubs/iterable.stub b/stubs/iterable.stub index 6f78862316..baf5ca9083 100644 --- a/stubs/iterable.stub +++ b/stubs/iterable.stub @@ -99,6 +99,13 @@ class SimpleXMLElement implements Traversable, ArrayAccess, Iterator, RecursiveI */ public function saveXML(?string $filename = null) { } + /** + * @param int|string|null $key + * @param self|string|int|float|bool $value + * @return void + */ + public function offsetSet($key, $value) {} + } /** diff --git a/tests/PHPStan/Rules/Arrays/OffsetAccessValueAssignmentRuleTest.php b/tests/PHPStan/Rules/Arrays/OffsetAccessValueAssignmentRuleTest.php index 4c9b910bad..4efada6991 100644 --- a/tests/PHPStan/Rules/Arrays/OffsetAccessValueAssignmentRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/OffsetAccessValueAssignmentRuleTest.php @@ -63,6 +63,11 @@ public function testRuleWithNullsafeVariant(): void ]); } + public function testBug8236(): void + { + $this->analyse([__DIR__ . '/data/bug-8236.php'], []); + } + #[RequiresPhp('>= 8.0')] public function testBug5655b(): void { diff --git a/tests/PHPStan/Rules/Arrays/data/bug-8236.php b/tests/PHPStan/Rules/Arrays/data/bug-8236.php new file mode 100644 index 0000000000..aae201a891 --- /dev/null +++ b/tests/PHPStan/Rules/Arrays/data/bug-8236.php @@ -0,0 +1,18 @@ +'); + $string = 'But isn\'t 7 > 5 & 9 < 11?'; + $node = $xml->a->addChild('formula1'); + if ($node !== null) { + $node[0] = $string; + } + echo $xml->asXML(); + } +} +HelloWorld::sayHello();