rfc:convert_numeric_keys_in_object_array_casts
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
rfc:convert_numeric_keys_in_object_array_casts [2016/10/21 21:22] ajf the separate THE |
rfc:convert_numeric_keys_in_object_array_casts [2017/11/30 14:49] ajf fixup |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Convert numeric keys in object/ | ====== PHP RFC: Convert numeric keys in object/ | ||
- | * Version: | + | * Version: 1.0 |
* Date: 2016-10-21 | * Date: 2016-10-21 | ||
* Author: Andrea Faulds, ajf@ajf.me | * Author: Andrea Faulds, ajf@ajf.me | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 10: | Line 10: | ||
The PHP language has two core data types which are collections of key/value pairs. | The PHP language has two core data types which are collections of key/value pairs. | ||
- | The first of these, the //array//, is an ordered map of integer or string keys to arbitrary values. There is no overlap between integer and string keys in arrays; if a string fits the format ''/ | + | The first of these, the //array//, is an ordered map of integer or string keys to arbitrary values. There is no overlap between integer and string keys in arrays; if a string fits the format ''/ |
The second of these, the //object//, is an ordered map of string property names to arbitrary values. Integer property names are not permitted, these are converted to string property names. Objects have some other attributes, but they do not concern us here. | The second of these, the //object//, is an ordered map of string property names to arbitrary values. Integer property names are not permitted, these are converted to string property names. Objects have some other attributes, but they do not concern us here. | ||
- | In the Zend Engine, both PHP arrays and PHP objects are internally represented using the same data structure, the '' | + | In the Zend Engine, both PHP arrays and PHP objects are internally represented using the same data structure, the '' |
- | Because arrays and objects have different restrictions versus the underlying HashTable type on what kinds of keys they can have than the, the Zend Engine must enforce their restrictions at a layer above HashTables, in the code implementing arrays and objects themselves. This means that if that code is bypassed and the underlying HashTables are modified directly, arrays and objects can exist with an invalid internal state. | + | Because arrays and objects have different restrictions versus the underlying HashTable type on what kinds of keys they can have, the Zend Engine must enforce their restrictions at a layer above HashTables, in the code implementing arrays and objects themselves. This means that if that code is bypassed and the underlying HashTables are modified directly, arrays and objects can exist with an invalid internal state. |
+ | |||
+ | < | ||
==== The Problem ==== | ==== The Problem ==== | ||
Line 22: | Line 24: | ||
Various edge cases in the Zend Engine exist where array HashTables can contain numeric string keys, and object HashTables can contain integer keys. In such cases, these keys are inaccessible from PHP code, because the code handling arrays will never look for numeric string keys in the HashTable (as arrays map those to integer keys), and the code handling objects will never look for integer keys in the HashTable (as objects map those to string keys). | Various edge cases in the Zend Engine exist where array HashTables can contain numeric string keys, and object HashTables can contain integer keys. In such cases, these keys are inaccessible from PHP code, because the code handling arrays will never look for numeric string keys in the HashTable (as arrays map those to integer keys), and the code handling objects will never look for integer keys in the HashTable (as objects map those to string keys). | ||
- | This RFC focuses on a specific edge case, that of object-to-array casts and array-to-object casts. Currently, when using < | + | This RFC focuses on a specific edge case, that of object-to-array casts and array-to-object casts. Currently, when using < |
===== Proposal ===== | ===== Proposal ===== | ||
Line 34: | Line 36: | ||
There have been attempts to fix this issue before, but there is a potential performance issue: naïvely copying the HashTable (or instead adding another reference to it if possible) without performing key conversion is much faster than creating a new HashTable and iterating over every key in the old HashTable to manually copy each key/value pair to the new HashTable, converting if necessary. | There have been attempts to fix this issue before, but there is a potential performance issue: naïvely copying the HashTable (or instead adding another reference to it if possible) without performing key conversion is much faster than creating a new HashTable and iterating over every key in the old HashTable to manually copy each key/value pair to the new HashTable, converting if necessary. | ||
- | In order to minimise the potential performance impact, the proposed implementation would avoid expensively manually duplicating the whole HashTable wherever possible, by first checking if this is necessary, either by checking flags (for example, [[http:// | + | In order to minimise the potential performance impact, the proposed implementation would avoid expensively manually duplicating the whole HashTable wherever possible, by first checking if this is necessary, either by checking flags (for example, [[http:// |
- | In the case of '' | + | In the case of <php>get_object_vars()</ |
For the purpose of these conversions, | For the purpose of these conversions, | ||
Line 81: | Line 83: | ||
Object/ | Object/ | ||
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
This could be construed as a language change, so this RFC requires a 2/3 majority in voting to be accepted. | This could be construed as a language change, so this RFC requires a 2/3 majority in voting to be accepted. | ||
- | There will be a single Yes/No vote on whether to accept the RFC and implement it in the proposed | + | It is a single Yes/No vote on whether to accept the RFC and implement it in PHP 7.2. Voting started on 2016-11-05 and ended on 2016-11-14. The result was to accept |
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | The pull request is here: https:// | + | The pull request |
+ | |||
+ | There is no language specification patch, because none is required. The language specification did not specify or comment on this bug. | ||
===== Implementation ===== | ===== Implementation ===== | ||
+ | |||
+ | This is implemented in master, which will become PHP 7.2. The commit is: https:// | ||
+ | |||
After the project is implemented, | After the project is implemented, | ||
- | - the version(s) it was merged to | ||
- | - a link to the git commit(s) | ||
- a link to the PHP manual entry for the feature | - a link to the PHP manual entry for the feature | ||
rfc/convert_numeric_keys_in_object_array_casts.txt · Last modified: 2017/11/30 14:50 by ajf