Skip to content

Commit 212948c

Browse files
Fix SimpleXMLElement::offsetSet
1 parent 9dbff97 commit 212948c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

stubs/iterable.stub

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class SimpleXMLElement implements Traversable, ArrayAccess, Iterator, RecursiveI
9999
*/
100100
public function saveXML(?string $filename = null) { }
101101

102+
/**
103+
* @param int|string|null $key
104+
* @param self|string|int|float|bool $value
105+
* @return void
106+
*/
107+
public function offsetSet($key, $value) {}
108+
102109
}
103110

104111
/**

tests/PHPStan/Rules/Arrays/OffsetAccessValueAssignmentRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public function testRuleWithNullsafeVariant(): void
6363
]);
6464
}
6565

66+
public function testBug8236(): void
67+
{
68+
$this->analyse([__DIR__ . '/data/bug-8236.php'], []);
69+
}
70+
6671
#[RequiresPhp('>= 8.0')]
6772
public function testBug5655b(): void
6873
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug8236;
4+
5+
class HelloWorld
6+
{
7+
public static function sayHello(): void
8+
{
9+
$xml = new \SimpleXmlElement('<root><a></a></root>');
10+
$string = 'But isn\'t 7 > 5 & 9 < 11?';
11+
$node = $xml->a->addChild('formula1');
12+
if ($node !== null) {
13+
$node[0] = $string;
14+
}
15+
echo $xml->asXML();
16+
}
17+
}
18+
HelloWorld::sayHello();

0 commit comments

Comments
 (0)