if (class_exists('SplFixedArray')) {
* The SplFixedArray class provides the main functionalities of array. The
* main differences between a SplFixedArray and a normal PHP array is that
* the SplFixedArray is of fixed length and allows only integers within
* the range as indexes. The advantage is that it allows a faster array
class SplFixedArray implements Iterator, ArrayAccess, Countable
/** @var array<int, mixed> */
private $internalArray = array();
* SplFixedArray constructor.
public function __construct($size = 0)
$this->internalArray = array();
return count($this->internalArray);
public function toArray()
ksort($this->internalArray);
return (array) $this->internalArray;
* @param bool $save_indexes
* @psalm-suppress MixedAssignment
public static function fromArray(array $array, $save_indexes = true)
$self = new SplFixedArray(count($array));
foreach($array as $key => $value) {
$self[(int) $key] = $value;
foreach (array_values($array) as $value) {
public function getSize()
public function setSize($size)
* @param string|int $index
public function offsetExists($index)
return array_key_exists((int) $index, $this->internalArray);
* @param string|int $index
public function offsetGet($index)
/** @psalm-suppress MixedReturnStatement */
return $this->internalArray[(int) $index];
* @param string|int $index
* @psalm-suppress MixedAssignment
public function offsetSet($index, $newval)
$this->internalArray[(int) $index] = $newval;
* @param string|int $index
public function offsetUnset($index)
unset($this->internalArray[(int) $index]);
* Rewind iterator back to the start
* @link https://php.net/manual/en/splfixedarray.rewind.php
reset($this->internalArray);
* Return current array entry
* @link https://php.net/manual/en/splfixedarray.current.php
* @return mixed The current element value.
public function current()
/** @psalm-suppress MixedReturnStatement */
return current($this->internalArray);
* Return current array index
* @return int The current array index.
return key($this->internalArray);
next($this->internalArray);
* Check whether the array contains more elements
* @link https://php.net/manual/en/splfixedarray.valid.php
* @return bool true if the array contains any more elements, false otherwise.
if (empty($this->internalArray)) {
$result = next($this->internalArray) !== false;
prev($this->internalArray);
public function __wakeup()