[doc-en] master: Split the illegal string offsets example output by PHP version (#5232)

From: Date: Mon, 31 Aug 2026 09:37:37 +0000
Subject: [doc-en] master: Split the illegal string offsets example output by PHP version (#5232)
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-23672@lists.php.net to get a copy of this message
Author: Louis-Arnaud (lacatoire) Committer: GitHub (web-flow) Pusher: lacatoire Date: 2026-08-31T11:37:34+02:00 Commit: https://github.com/php/doc-en/commit/eb4bde8a489ee6523879baa482247ed49aea951d Raw diff: https://github.com/php/doc-en/commit/eb4bde8a489ee6523879baa482247ed49aea951d.diff Split the illegal string offsets example output by PHP version (#5232) The output shown for the example was already corrected in master; what the issue thread still asked for was making the version difference visible. Split the output into two sections with example.outputs.8 and example.outputs.7, and state the PHP 8 rule in the introductory paragraph. State the PHP 8 rule as it actually is. A string starting with an integer followed by other characters, such as "1x", does not throw a TypeError: it still emits E_WARNING and is read as its leading integer, which the PHP 8 output of this very example shows. Only the other non-integer-like strings throw. The PHP 7 output is what PHP 7 really prints: isset() rejects every offset that is not integer-like, so it is false for both '1.0' and '1x', and '1x' emits "A non well formed numeric value encountered" rather than an illegal offset warning, since the read path allows trailing data. Sources: - Zend/zend_execute.c, zend_isset_dim_slow() and the string branch of zend_fetch_dimension_address_read(); Zend/zend_operators.c, _is_numeric_string_ex() - Zend/tests/offset_string.phpt and Zend/tests/isset_str_offset.phpt in 7.4 - PHP 8 output verified against PHP 8.5.4 Changed paths: M language/types/string.xml Diff: diff --git a/language/types/string.xml b/language/types/string.xml index 8aae48aefd5e..b5bfbcab8f83 100644 --- a/language/types/string.xml +++ b/language/types/string.xml @@ -1088,10 +1088,15 @@ var_dump($str); </programlisting> </example> - <para> - String offsets have to either be integers or integer-like strings, - otherwise a warning will be thrown. - </para> + <simpara> + String offsets must be either integers or integer-like strings. + As of PHP 8.0.0, any other string throws a + <exceptionname>TypeError</exceptionname>, except for a string starting + with an integer followed by other characters, which emits + <constant>E_WARNING</constant> and is interpreted as that leading integer. + Prior to PHP 8.0.0, no <exceptionname>TypeError</exceptionname> was + thrown: an illegal offset emitted <constant>E_WARNING</constant> instead. + </simpara> <example> <title>Example of Illegal String Offsets</title> @@ -1116,7 +1121,7 @@ foreach ($keys as $keyToTry) { ?> ]]> </programlisting> - &example.outputs; + &example.outputs.8; <screen> <![CDATA[ bool(true) @@ -1130,7 +1135,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>

« previous php.doc.cvs (#23672) next »