wppaste
WordPress

SplFixedArray

Source
wp-includes/sodium_compat/src/PHP52/SplFixedArray.php:14
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 implementation.

Compatibility

WordPress
core
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 2

$internalArrayarray<int,private
$sizeintprivate

Methods · 19

Source code

class SplFixedArray implements Iterator, ArrayAccess, Countable{    /** @var array<int, mixed> */    private $internalArray = array();     /** @var int $size */    private $size = 0;     /**     * SplFixedArray constructor.     * @param int $size     */    public function __construct($size = 0)    {        $this->size = $size;        $this->internalArray = array();    }     /**     * @return int     */    #[\ReturnTypeWillChange]    public function count()    {        return count($this->internalArray);    }     /**     * @return array     */    public function toArray()    {        ksort($this->internalArray);        return (array) $this->internalArray;    }     /**     * @param array $array     * @param bool $save_indexes     * @return SplFixedArray     * @psalm-suppress MixedAssignment     */    public static function fromArray(array $array, $save_indexes = true)    {        $self = new SplFixedArray(count($array));        if($save_indexes) {            foreach($array as $key => $value) {                $self[(int) $key] = $value;            }        } else {            $i = 0;            foreach (array_values($array) as $value) {                $self[$i] = $value;                $i++;            }        }        return $self;    }     /**     * @return int     */    #[\ReturnTypeWillChange]    public function getSize()    {        return $this->size;    }     /**     * @param int $size     * @return bool     */    #[\ReturnTypeWillChange]    public function setSize($size)    {        $this->size = $size;        return true;    }     /**

Changelog

3 changes between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.9.7
Method __sleep() added.verified against source
6.9.7
Method __serialize() added.verified against source
6.9.7
Method __unserialize() added.verified against source

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/sodium_compat/src/PHP52/SplFixedArray.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.