Skip to content

Commit cacc8bb

Browse files
authored
Fixed stub types for SplFixedArray
1 parent da3790e commit cacc8bb

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

stubs/ArrayObject.stub

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ class ArrayObject implements IteratorAggregate, ArrayAccess
8888

8989
/**
9090
* @template TValue
91-
* @implements Iterator<int, TValue>
92-
* @implements IteratorAggregate<int, TValue>
93-
* @implements ArrayAccess<int, TValue>
91+
* @implements Iterator<int, TValue|null>
92+
* @implements IteratorAggregate<int, TValue|null>
93+
* @implements ArrayAccess<int, TValue|null>
9494
*/
9595
class SplFixedArray implements Iterator, IteratorAggregate, ArrayAccess, Countable
9696
{
@@ -102,7 +102,7 @@ class SplFixedArray implements Iterator, IteratorAggregate, ArrayAccess, Countab
102102
public static function fromArray(array $array, bool $save_indexes = true): SplFixedArray { }
103103

104104
/**
105-
* @return array<int, TValue>
105+
* @return array<int, TValue|null>
106106
*/
107107
public function toArray(): array { }
108108
}

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ public function dataFileAsserts(): iterable
446446
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5129.php');
447447
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4970.php');
448448
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5322.php');
449+
yield from $this->gatherAssertTypes(__DIR__ . '/data/splfixedarray-iterator-types.php');
449450
}
450451

451452
/**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
class HelloWorld
4+
{
5+
/**
6+
* @var int[]|\SplFixedArray
7+
* @phpstan-var \SplFixedArray<int>
8+
*/
9+
public $array;
10+
11+
public function dump() : void{
12+
foreach($this->array as $id => $v){
13+
\PHPStan\Testing\assertType('int|null', $this->array[$id]);
14+
\PHPStan\Testing\assertType('int|null', $v);
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)