&class.theclass; SplFixedArray
SplFixedArray
&reftitle.intro;
La classe SplFixedArray fournit les fonctionnalités
principales d'un tableau. La différence majeure entre un objet
SplFixedArray et un &array; standard de PHP est
que SplFixedArray doit être redimensionné manuellement, et
n'utilise que des &integer; dans cette plage pour les index. L'avantage est qu'il utilise
moins de mémoire qu'un &array; standard.
&reftitle.classsynopsis;
SplFixedArray
implements
IteratorAggregate
ArrayAccess
Countable
JsonSerializable
&Methods;
&reftitle.changelog;
&Version;
&Description;
8.2.0
Les méthodes magiques SplFixedArray::__serialize
et SplFixedArray::__unserialize
ont été ajoutées à SplFixedArray.
8.1.0
La classe SplFixedArray implémente désormais JsonSerializable.
8.0.0
La classe SplFixedArray implémente désormais IteratorAggregate.
Auparavant, Iterator était implémentée.
&reftitle.examples;
Exemple avec SplFixedArray
setSize(10);
$array[9] = "asdf";
// Réduction de taille de 2
$array->setSize(2);
// Les lignes suivantes émettent une RuntimeException : index invalide ou hors de l'intervalle
try {
var_dump($array["non-numeric"]);
} catch(RuntimeException $re) {
echo "RuntimeException : ".$re->getMessage()."\n";
}
try {
var_dump($array[-1]);
} catch(RuntimeException $re) {
echo "RuntimeException : ".$re->getMessage()."\n";
}
try {
var_dump($array[5]);
} catch(RuntimeException $re) {
echo "RuntimeException : ".$re->getMessage()."\n";
}
?>
]]>
&example.outputs;
&reference.spl.entities.splfixedarray;