rfc:negative_array_index
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:negative_array_index [2017/04/20 22:47] – pmmaga | rfc:negative_array_index [2020/08/01 23:40] (current) – RFC was implemented in both PHP 7.4 and PHP 8.0 carusogabriel | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Arrays starting with a negative index ====== | ====== PHP RFC: Arrays starting with a negative index ====== | ||
- | * Version: 0.1 | + | * Version: 0.4 |
* Date: 2017-04-20 | * Date: 2017-04-20 | ||
- | * Author: Pedro Magalhães, | + | * Author: Pedro Magalhães, pmmaga@php.net |
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | Currently, any array that has a number '' | + | On the documentation |
===== Proposal ===== | ===== Proposal ===== | ||
- | As mentioned on the relevant part of the [[http:// | + | In other words, any array that has a number '' |
+ | |||
+ | As also mentioned on the relevant part of the [[http:// | ||
> if no key is specified, the maximum of the existing integer indices is taken, and the new key will be that maximum value plus 1 (but at least 0). | > if no key is specified, the maximum of the existing integer indices is taken, and the new key will be that maximum value plus 1 (but at least 0). | ||
This RFC proposes to eliminate the parenthesis part of that sentence. Which is an exception to a rule, that people have to learn one way or the other. | This RFC proposes to eliminate the parenthesis part of that sentence. Which is an exception to a rule, that people have to learn one way or the other. | ||
+ | |||
+ | This proposal targets 8.0. However, to ease the transition and find places where this may become an issue, there is a secondary vote for emitting a deprecation notice in cases where the behavior will change. | ||
All the variables in this code: | All the variables in this code: | ||
Line 41: | Line 45: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | < | ||
+ | NOTE: If accepted, during the deprecation phase the following '' | ||
+ | |||
+ | < | ||
+ | Deprecated: In the next major version of PHP the implicit keys of this array will start from -1 instead of 0 in ... | ||
+ | </ | ||
+ | </ | ||
With the implementation of this RFC, they will all result in: | With the implementation of this RFC, they will all result in: | ||
Line 61: | Line 73: | ||
<?php | <?php | ||
- | $a[-2] = true; | + | $a[-2] = true; // Current: Key is -2, RFC: Key is -2 |
- | $a[] = true; | + | $a[] = true; // Current: Key is 0, RFC: Key is -1 |
- | $a[] = true; | + | $a[] = true; // Current: Key is 1, RFC: Key is 0 |
if ($a[1] === true) { | if ($a[1] === true) { | ||
- | echo 'Save the world.'; | + | echo 'Accessing key 1 explicitly'; |
} | } | ||
</ | </ | ||
- | Will no longer | + | Will no longer |
+ | |||
+ | < | ||
+ | NOTE: If accepted, during the deprecation phase the '' | ||
+ | </ | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | PHP 7.2 | + | PHP 8.0 |
+ | (Deprecation notice for 7.3) | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
- | Arrays with explicit keys, string keys, or an initial numeric index ''> | + | Arrays with explicit keys, string keys, or an initial numeric index ''> |
- | Furthermore, | + | Furthermore, |
- | ===== Proposed | + | ===== Voting Choices ===== |
- | This RFC requires | + | Both votes require |
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | < | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
Line 89: | Line 120: | ||
===== References ===== | ===== References ===== | ||
- | Discussion on the mailing list: | + | Version 0.3: |
+ | |||
+ | Discussion on the mailing list: https:// | ||
+ | |||
+ | First proposal Voting period discussion: https:// | ||
+ | |||
+ | Second proposal Voting period discussion: https:// | ||
+ | |||
+ | ---- | ||
+ | Version 0.4: | ||
+ | Discussion on the mailing list: https:// |
rfc/negative_array_index.1492728456.txt.gz · Last modified: 2017/09/22 13:28 (external edit)