diff options
| author | Alex Dowad <alexinbeijing@gmail.com> | 2020-05-11 20:32:13 +0200 |
|---|---|---|
| committer | Alex Dowad <alexinbeijing@gmail.com> | 2020-09-23 08:33:24 +0200 |
| commit | 4222ae16e7848e0b3f062a9a989d387de307a7af (patch) | |
| tree | 049e87edb7c167065cf8399943323d4451dc69cd /ext/spl/spl_fixedarray.stub.php | |
| parent | 1e9db80d7264911fa4089cb7e4b3dc7f97b19c6e (diff) | |
| download | php-git-4222ae16e7848e0b3f062a9a989d387de307a7af.tar.gz | |
SplFixedArray is Aggregate, not Iterable
One strange feature of SplFixedArray was that it could not be used in nested foreach
loops. If one did so, the inner loop would overwrite the iteration state of the outer
loop.
To illustrate:
$spl = SplFixedArray::fromArray([0, 1]);
foreach ($spl as $a) {
foreach ($spl as $b) {
echo "$a $b";
}
}
Would only print two lines:
0 0
0 1
Use the new InternalIterator feature which was introduced in ff19ec2df3 to convert
SplFixedArray to an Aggregate rather than Iterable. As a bonus, we get to trim down
some ugly code! Yay!
Diffstat (limited to 'ext/spl/spl_fixedarray.stub.php')
| -rwxr-xr-x | ext/spl/spl_fixedarray.stub.php | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/ext/spl/spl_fixedarray.stub.php b/ext/spl/spl_fixedarray.stub.php index 553de5c2fa..b169dfdeac 100755 --- a/ext/spl/spl_fixedarray.stub.php +++ b/ext/spl/spl_fixedarray.stub.php @@ -2,7 +2,7 @@ /** @generate-function-entries */ -class SplFixedArray implements Iterator, ArrayAccess, Countable +class SplFixedArray implements IteratorAggregate, ArrayAccess, Countable { public function __construct(int $size = 0) {} @@ -48,18 +48,5 @@ class SplFixedArray implements Iterator, ArrayAccess, Countable */ public function offsetUnset($index) {} - /** @return void */ - public function rewind() {} - - /** @return mixed */ - public function current() {} - - /** @return int */ - public function key() {} - - /** @return void */ - public function next() {} - - /** @return bool */ - public function valid() {} + public function getIterator(): Iterator {} } |
