From ede1cf388b1347daaccc82891b9b5c6bcbc15647 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 27 Sep 2023 04:17:24 +0100 Subject: [PATCH 1/7] Update range() documentation for PHP 8.3 changes TODO Better examples --- reference/array/functions/range.xml | 186 +++++++++++++++++++++++++--- 1 file changed, 170 insertions(+), 16 deletions(-) diff --git a/reference/array/functions/range.xml b/reference/array/functions/range.xml index 6f2c32b89180..154b52c57fad 100644 --- a/reference/array/functions/range.xml +++ b/reference/array/functions/range.xml @@ -1,5 +1,4 @@ - range @@ -16,7 +15,19 @@ Create an array containing a range of elements. + + If both start and end are + strings, and step is int + the produced array will be a sequence of characters. + Otherwise, the produced array will be a sequence of numbers. + + + The sequence is increasing if start is less + or equal than end. + Otherwise, the sequence is decreasing. + + &reftitle.parameters; @@ -33,8 +44,7 @@ end - The sequence is ended upon reaching the - end value. + Last possible value of the sequence. @@ -42,23 +52,174 @@ step - If a step value is given, it will be used as the - increment (or decrement) between elements in the sequence. step - must not equal 0 and must not exceed the specified range. If not specified, - step will default to 1. + By default 1. + step indicates by how much is the produced + sequence progressed between values of the sequence. + + + step may be negative for decreasing sequences. + + + If step is a float without a + fractional part, it is interpreted as int. + &reftitle.returnvalues; Returns an array of elements from start to end, inclusive. + + If both start and end are + strings, and step is int + the produced array will be a sequence of characters. + + + If start, end, + or step is float + the produced array will be a sequence of float. + + + Otherwise, the produced array will be a sequence of int. + + + + + &reftitle.errors; + + A ValueError is thrown if + step is 0. + + + A ValueError is thrown if the value of + start, end, + or, as of PHP 8.3.0, step is not finite. + I.e. the value is infinity or NAN. + + + As of PHP 8.3.0, a ValueError is thrown if the + value of step is negative but the produced range + is increasing. I.e. $start <= $end. + + + As of PHP 8.3.0, an E_WARNING is emitted if + start or end are the empty + string ''. + The empty string will be interpreted as 0. + + + As of PHP 8.3.0, an E_WARNING is emitted if + start or end is the empty + string ''. + The empty string will be interpreted as 0. + + + As of PHP 8.3.0, an E_WARNING is emitted if + start or end is a non-numeric + string with more than one byte. + + + As of PHP 8.3.0, an E_WARNING is emitted if + start or end is a string + that is implicitly cast to an int because the other boundary + value is a number. + + + As of PHP 8.3.0, an E_WARNING is emitted if + step is a float, and + start and end + are non-numeric strings. + + + + + &reftitle.changelog; + + + + + &Version; + &Description; + + + + + 8.3.0 + + If both start and end + are strings then range will now always produce + an array of characters. + Previously if one of the boundary values was a numeric string, + then the other boundary value was implicitly cast to int. + + + + 8.3.0 + + An E_WARNING is now emitted if + start or end + is a string that is implicitly cast to int + because the other boundary value is a number. + + + + 8.3.0 + + An E_WARNING is now emitted if + start or end + is a non-numeric string with more than one byte. + + + + 8.3.0 + + An E_WARNING is now emitted if + start or end + is the empty string. + + + + 8.3.0 + + If step is a float with no + fractional part, it will be interpreted as an int. + + + + 8.3.0 + + A ValueError is now thrown if + step is negative when producing an increasing + range. + + + + 8.3.0 + + A ValueError is now thrown if + step is not finite. + + + + 8.3.0 + + A TypeError is now thrown if + start or end + is an array, object, or resource. + Previously they were implicitly cast to int. + + + + + + &reftitle.examples; @@ -100,15 +261,7 @@ foreach (range('c', 'a') as $letter) { - - &reftitle.notes; - - - Character sequence values are limited to a length of one. If a length greater - than one is entered, only the first character is used. - - - + &reftitle.seealso; @@ -119,6 +272,7 @@ foreach (range('c', 'a') as $letter) { +