Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions language/types/string.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 0d964bcaac6618dd80b974eb6fcdf3c67ca07340 Maintainer: PhilDaiguille Status: ready -->
<!-- EN-Revision: eb4bde8a489ee6523879baa482247ed49aea951d Maintainer: PhilDaiguille Status: ready -->
<sect1 xml:id="language.types.string">
<title>Cadenas</title>

Expand Down Expand Up @@ -1061,10 +1061,16 @@ var_dump($str);
</programlisting>
</example>

<para>
Los offsets de string deben ser enteros o strings que parezcan enteros,
de lo contrario se emitirá una advertencia.
</para>
<simpara>
Los offsets de string deben ser enteros o strings que parezcan enteros. A
partir de PHP 8.0.0, cualquier otra string lanza un
<exceptionname>TypeError</exceptionname>, salvo una string que comience por
un entero seguido de otros caracteres, que emite un
<constant>E_WARNING</constant> y se interpreta como ese entero inicial.
Anterior a PHP 8.0.0, no se lanzaba ningún
<exceptionname>TypeError</exceptionname>: un offset ilegal emitía un
<constant>E_WARNING</constant> en su lugar.
</simpara>

<example>
<title>Ejemplo de offsets de string ilegales</title>
Expand All @@ -1073,6 +1079,8 @@ var_dump($str);
<?php
$str = 'abc';

$keys = [ '1', '1.0', 'x', '1x' ];

foreach ($keys as $keyToTry) {
var_dump(isset($str[$keyToTry]));

Expand All @@ -1087,7 +1095,7 @@ foreach ($keys as $keyToTry) {
?>
]]>
</programlisting>
&example.outputs;
&example.outputs.8;
<screen>
<![CDATA[
bool(true)
Expand All @@ -1101,7 +1109,29 @@ Cannot access offset of type string on string

bool(false)

Warning: Illegal string offset "1x" in Standard input code on line 10
Warning: Illegal string offset "1x" in example.php on line 10
string(1) "b"
]]>
</screen>
&example.outputs.7;
<screen>
<![CDATA[
bool(true)
string(1) "b"

bool(false)

Warning: Illegal string offset '1.0' in example.php on line 10
string(1) "b"

bool(false)

Warning: Illegal string offset 'x' in example.php on line 10
string(1) "a"

bool(false)

Notice: A non well formed numeric value encountered in example.php on line 10
string(1) "b"
]]>
</screen>
Expand Down