SplFixedArray stores values in numbered slots with a fixed size.

fixed slots Use a fixed array when the number of slots is known and each slot has a stable index.

SPL Fixed Array

slot
spl_fixed_array.php
Replay: real traced execution (multi-file project)
<?php
$slot = 1;
$items = new SplFixedArray(3);
$items[0] = "red";
$items[1] = "blue";
$items[2] = "green";
$chosen = $items[$slot];
$count = $items->count();

echo "slot=" . $slot . "\n";
echo "chosen=" . $chosen . "\n";
echo "count=" . $count . "\n";
<?php
$slot = 0;
$items = new SplFixedArray(3);
$items[0] = "red";
$items[1] = "blue";
$items[2] = "green";
$chosen = $items[$slot];
$count = $items->count();

echo "slot=" . $slot . "\n";
echo "chosen=" . $chosen . "\n";
echo "count=" . $count . "\n";
<?php
$slot = 2;
$items = new SplFixedArray(3);
$items[0] = "red";
$items[1] = "blue";
$items[2] = "green";
$chosen = $items[$slot];
$count = $items->count();

echo "slot=" . $slot . "\n";
echo "chosen=" . $chosen . "\n";
echo "count=" . $count . "\n";
  1. $slot ← 1, $items ← SplFixedArray, $items[0] ← red, $items[1] ← blue

    1<?php2$slot→ 1 = 1; //@slot=0, 23$items→ SplFixedArray = new SplFixedArray(3);4$items[0]→ red = "red";5$items[1]→ blue = "blue";6$items[2]→ green = "green";7$chosen→ blue = $items[$slot]blue;8$count→ 3 = $itemsSplFixedArray->count();910echo "slot=" . $slot1 . "\n";11echo "chosen=" . $chosenblue . "\n";12echo "count=" . $count3 . "\n";
    outputslot=1
    chosen=blue
    count=3
  1. $slot ← 0, $items ← SplFixedArray, $items[0] ← red, $items[1] ← blue

    1<?php2$slot→ 0 = 0;3$items→ SplFixedArray = new SplFixedArray(3);4$items[0]→ red = "red";5$items[1]→ blue = "blue";6$items[2]→ green = "green";7$chosen→ red = $items[$slot]red;8$count→ 3 = $itemsSplFixedArray->count();910echo "slot=" . $slot0 . "\n";11echo "chosen=" . $chosenred . "\n";12echo "count=" . $count3 . "\n";
    outputslot=0
    chosen=red
    count=3
  1. $slot ← 2, $items ← SplFixedArray, $items[0] ← red, $items[1] ← blue

    1<?php2$slot→ 2 = 2;3$items→ SplFixedArray = new SplFixedArray(3);4$items[0]→ red = "red";5$items[1]→ blue = "blue";6$items[2]→ green = "green";7$chosen→ green = $items[$slot]green;8$count→ 3 = $itemsSplFixedArray->count();910echo "slot=" . $slot2 . "\n";11echo "chosen=" . $chosengreen . "\n";12echo "count=" . $count3 . "\n";
    outputslot=2
    chosen=green
    count=3