From bc0f66994c70cec0b8f676c77fb444c9161718f3 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Thu, 27 Aug 2026 17:44:36 +0200 Subject: [PATCH] [Sync-En] SplFixedArray: non-integer key throws TypeError as of PHP 8.1.0 --- reference/spl/splfixedarray.xml | 42 +++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/reference/spl/splfixedarray.xml b/reference/spl/splfixedarray.xml index deb291abc..ff2647c1b 100644 --- a/reference/spl/splfixedarray.xml +++ b/reference/spl/splfixedarray.xml @@ -1,6 +1,5 @@ - - + La clase SplFixedArray SplFixedArray @@ -88,6 +87,14 @@ a SplFixedArray. + + 8.1.0 + + El uso de una clave no entera en un SplFixedArray + ahora lanza un TypeError en lugar de una + RuntimeException. + + 8.1.0 @@ -136,23 +143,25 @@ $array[9] = "asdf"; // Reducir el tamaño de un array a 2 $array->setSize(2); -// Las siguientes líneas lanzan una RuntimeException: Index invalid or out of range (Índice inválido o fuera de rango) +// Los dos bloques siguientes lanzan una RuntimeException: Index invalid or out of range (Índice inválido o fuera de rango) try { - var_dump($array["non-numeric"]); -} catch(RuntimeException $re) { - echo "RuntimeException: ".$re->getMessage()."\n"; + var_dump($array[-1]); +} catch(RuntimeException $e) { + echo "RuntimeException: ".$e->getMessage()."\n"; } try { - var_dump($array[-1]); -} catch(RuntimeException $re) { - echo "RuntimeException: ".$re->getMessage()."\n"; + var_dump($array[5]); +} catch(RuntimeException $e) { + echo "RuntimeException: ".$e->getMessage()."\n"; } +// A partir de PHP 8.1.0, el uso de una clave no entera lanza un TypeError. +// Antes de PHP 8.1.0, se lanzaba una RuntimeException en su lugar. try { - var_dump($array[5]); -} catch(RuntimeException $re) { - echo "RuntimeException: ".$re->getMessage()."\n"; + var_dump($array["non-numeric"]); +} catch(TypeError $e) { + echo "TypeError: ".$e->getMessage()."\n"; } ?> ]]> @@ -165,11 +174,18 @@ int(2) string(3) "foo" RuntimeException: Index invalid or out of range RuntimeException: Index invalid or out of range -RuntimeException: Index invalid or out of range +TypeError: Illegal offset type ]]> + + + Antes de PHP 8.1.0, acceder a un SplFixedArray con + una clave no entera lanzaba una RuntimeException + en lugar de un TypeError. + +