rfc:proper-range-semantics
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:proper-range-semantics [2023/05/08 09:24] – Clarification nits girgias | rfc:proper-range-semantics [2023/06/01 16:16] – In voting girgias | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Define proper semantics for range() function | ====== PHP RFC: Define proper semantics for range() function | ||
- | * Version: 0.2 | + | * Version: 0.3 |
* Date: 2023-03-13 | * Date: 2023-03-13 | ||
* Author: George Peter Banyard, < | * Author: George Peter Banyard, < | ||
- | * Status: | + | * Status: |
* Target Version: PHP 8.3 | * Target Version: PHP 8.3 | ||
* Implementation: | * Implementation: | ||
Line 19: | Line 19: | ||
The current behaviour is quite complex, and it might be easier to just read the implementation, | The current behaviour is quite complex, and it might be easier to just read the implementation, | ||
- | First, check if the < | + | First, check if the < |
Then check the boundary arguments: | Then check the boundary arguments: | ||
* If both start and end values are strings with at least one byte (e.g. < | * If both start and end values are strings with at least one byte (e.g. < | ||
- | * If one of the inputs is a float numeric string, or the < | + | * If one of the inputs is a float numeric string, or the < |
- | * If one of the inputs is an integer numeric string: go to the generic handling branch | + | * If one of the inputs is an integer numeric string: go to the generic handling branch. |
* Otherwise: discard every byte after the first one and return an array of ASCII characters going from the start ASCII code point to the end ASCII code point. | * Otherwise: discard every byte after the first one and return an array of ASCII characters going from the start ASCII code point to the end ASCII code point. | ||
- | * If one of the start or end value is a float or the < | + | * If the start or end value is a float or the < |
- | * Otherwise (generic handling): cast start and end values to int and return an array of int. | + | * Otherwise (generic handling): cast start and end values to int and return an array of integers. |
| | ||
The generic case will accept //any// type. | The generic case will accept //any// type. | ||
Line 132: | Line 132: | ||
[4] | [4] | ||
string(1) " | string(1) " | ||
+ | } | ||
+ | |||
+ | |||
+ | var_dump(range(' | ||
+ | array(3) { | ||
+ | [0]=> | ||
+ | int(1) | ||
+ | [1]=> | ||
+ | int(2) | ||
+ | [2]=> | ||
+ | int(3) | ||
} | } | ||
</ | </ | ||
Line 322: | Line 333: | ||
==== Issues surrounding usage of INF and NAN values ==== | ==== Issues surrounding usage of INF and NAN values ==== | ||
- | Infinite values are handles | + | Infinite values are handled |
However, NAN values are not specifically handled and result in nonsensical ranges: | However, NAN values are not specifically handled and result in nonsensical ranges: | ||
Line 339: | Line 350: | ||
</ | </ | ||
- | Where using a NAN values | + | Where using a NAN value as a step even breaks the expectation that < |
+ | ==== Issues surrounding usage of string digits ==== | ||
+ | |||
+ | If one of the boundary inputs is a string digit (e.g. ''" | ||
+ | This doesn' | ||
+ | |||
+ | However, if the other input is a non-numeric string the expected behaviour of generating a list of ASCII characters is not upheld anymore: | ||
+ | <PHP> | ||
+ | var_dump( range(" | ||
+ | array(10) { | ||
+ | [0]=> | ||
+ | int(9) | ||
+ | [1]=> | ||
+ | int(8) | ||
+ | [2]=> | ||
+ | int(7) | ||
+ | [3]=> | ||
+ | int(6) | ||
+ | [4]=> | ||
+ | int(5) | ||
+ | [5]=> | ||
+ | int(4) | ||
+ | [6]=> | ||
+ | int(3) | ||
+ | [7]=> | ||
+ | int(2) | ||
+ | [8]=> | ||
+ | int(1) | ||
+ | [9]=> | ||
+ | int(0) | ||
+ | } | ||
+ | </ | ||
+ | instead of the expected: | ||
+ | <PHP> | ||
+ | var_dump( range(" | ||
+ | array(9) { | ||
+ | [0]=> | ||
+ | string(1) " | ||
+ | [1]=> | ||
+ | string(1) ":" | ||
+ | [2]=> | ||
+ | string(1) ";" | ||
+ | [3]=> | ||
+ | string(1) "<" | ||
+ | [4]=> | ||
+ | string(1) " | ||
+ | [5]=> | ||
+ | string(1) ">" | ||
+ | [6]=> | ||
+ | string(1) "?" | ||
+ | [7]=> | ||
+ | string(1) " | ||
+ | [8]=> | ||
+ | string(1) " | ||
+ | } | ||
+ | </ | ||
===== Proposal ===== | ===== Proposal ===== | ||
Line 349: | Line 415: | ||
* If < | * If < | ||
- | * Introduce and use a proper ZPP check for '' | + | * Introduce and use a proper ZPP check for '' |
* Throw value errors if < | * Throw value errors if < | ||
* Throw a more descriptive < | * Throw a more descriptive < | ||
Line 355: | Line 421: | ||
* Emit an < | * Emit an < | ||
* Emit an < | * Emit an < | ||
- | * Emit an < | + | * Emit an < |
- | * Emit an < | + | * Produce a list of characters if one of the boundary inputs is a string digit instead of casting the other input to int (e.g. < |
+ | * Emit an < | ||
Line 375: | Line 442: | ||
[4]=> | [4]=> | ||
string(1) " | string(1) " | ||
+ | } | ||
+ | |||
+ | var_dump( range(" | ||
+ | array(9) { | ||
+ | [0]=> | ||
+ | string(1) " | ||
+ | [1]=> | ||
+ | string(1) ":" | ||
+ | [2]=> | ||
+ | string(1) ";" | ||
+ | [3]=> | ||
+ | string(1) "<" | ||
+ | [4]=> | ||
+ | string(1) " | ||
+ | [5]=> | ||
+ | string(1) ">" | ||
+ | [6]=> | ||
+ | string(1) "?" | ||
+ | [7]=> | ||
+ | string(1) " | ||
+ | [8]=> | ||
+ | string(1) " | ||
} | } | ||
Line 436: | Line 525: | ||
< | < | ||
- | Calls to < | + | Calls to < |
<PHP> | <PHP> | ||
var_dump( range(1, 5, 2.0) ); | var_dump( range(1, 5, 2.0) ); | ||
Line 467: | Line 556: | ||
As per the voting RFC a yes/no vote with a 2/3 majority is needed for this proposal to be accepted. | As per the voting RFC a yes/no vote with a 2/3 majority is needed for this proposal to be accepted. | ||
- | Voting started on 2023-XX-XX and will end on 2023-XX-XX. | + | Voting started on 2023-06-01 and will end on 2023-06-15. |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No |
rfc/proper-range-semantics.txt · Last modified: 2023/06/19 13:41 by girgias