mirror of
https://github.com/php/php-src.git
synced 2026-03-25 16:52:18 +01:00
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!
53 lines
1.0 KiB
PHP
Executable File
53 lines
1.0 KiB
PHP
Executable File
<?php
|
|
|
|
/** @generate-function-entries */
|
|
|
|
class SplFixedArray implements IteratorAggregate, ArrayAccess, Countable
|
|
{
|
|
public function __construct(int $size = 0) {}
|
|
|
|
/** @return void */
|
|
public function __wakeup() {}
|
|
|
|
/** @return int */
|
|
public function count() {}
|
|
|
|
/** @return array */
|
|
public function toArray() {}
|
|
|
|
/** @return SplFixedArray */
|
|
public static function fromArray(array $array, bool $save_indexes = true) {}
|
|
|
|
/** @return int */
|
|
public function getSize() {}
|
|
|
|
/** @return bool */
|
|
public function setSize(int $size) {}
|
|
|
|
/**
|
|
* @param int $index
|
|
* @return bool
|
|
*/
|
|
public function offsetExists($index) {}
|
|
|
|
/**
|
|
* @param int $index
|
|
* @return mixed
|
|
*/
|
|
public function offsetGet($index) {}
|
|
|
|
/**
|
|
* @param int $index
|
|
* @return void
|
|
*/
|
|
public function offsetSet($index, mixed $value) {}
|
|
|
|
/**
|
|
* @param int $index
|
|
* @return void
|
|
*/
|
|
public function offsetUnset($index) {}
|
|
|
|
public function getIterator(): Iterator {}
|
|
}
|