rfc:container-offset-behaviour
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:container-offset-behaviour [2024/07/09 23:29] – Make this a h5 as apparently Dokuwiki does not support h6 headings... girgias | rfc:container-offset-behaviour [2024/07/30 09:47] (current) – Move target version girgias | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Improve language coherence for the behaviour of offsets and containers ====== | ====== PHP RFC: Improve language coherence for the behaviour of offsets and containers ====== | ||
- | * Version: 0.2 | + | * Version: 0.3 |
* Date: 2023-12-07 | * Date: 2023-12-07 | ||
* Author: Gina Peter Banyard < | * Author: Gina Peter Banyard < | ||
* Status: Under Discussion | * Status: Under Discussion | ||
- | * Target Version: PHP 8.4 | + | * Target Version: PHP 8.5 |
* Implementations: | * Implementations: | ||
- | | + | |
- | * < | + | * < |
- | * Original string offset clean-up PR: < | + | * Original string offset clean-up PR: < |
* First Published at: < | * First Published at: < | ||
* Markdown source: < | * Markdown source: < | ||
Line 32: | Line 32: | ||
==== Operations ==== | ==== Operations ==== | ||
- | We consider there to be nine (9) different operations that relate to containers and offsets, | + | We consider there to be ten (10) different operations that relate to containers and offsets, |
which are the following: | which are the following: | ||
Line 44: | Line 44: | ||
* Fetch | * Fetch | ||
* Fetch-Append | * Fetch-Append | ||
+ | * Incrementing/ | ||
The read, write, read-write, appending, and unsetting operations are what one would expect. | The read, write, read-write, appending, and unsetting operations are what one would expect. | ||
Line 60: | Line 61: | ||
In general, a nested operation will perform all the necessary fetch/read operations, | In general, a nested operation will perform all the necessary fetch/read operations, | ||
interpreting the returned value as a container, until it reaches the final dimension. | interpreting the returned value as a container, until it reaches the final dimension. | ||
+ | |||
+ | Finally, we mention incrementing/ | ||
+ | but as it works on a " | ||
==== Container types ==== | ==== Container types ==== | ||
Line 68: | Line 72: | ||
* < | * < | ||
* < | * < | ||
- | * < | ||
* < | * < | ||
* < | * < | ||
Line 120: | Line 123: | ||
* For read operations, < | * For read operations, < | ||
- | * For write, read-write, appending, fetch, | + | * For write, read-write, appending, fetch, fetch-append, and increment/ |
* For the unset operation, the following error is thrown:< | * For the unset operation, the following error is thrown:< | ||
Line 144: | Line 147: | ||
* For write, append, fetch, and fetch-append operations the container is converted to array. And thus behave like an < | * For write, append, fetch, and fetch-append operations the container is converted to array. And thus behave like an < | ||
- | * For read-write operations, the container is converted to array, before the read operation. And thus behave like an < | + | * For read-write |
* For the unset operation, the container continues to be < | * For the unset operation, the container continues to be < | ||
Line 161: | Line 164: | ||
* For write, append, fetch, and fetch-append operations the container is converted to array, Emitting the following deprecation notice:< | * For write, append, fetch, and fetch-append operations the container is converted to array, Emitting the following deprecation notice:< | ||
- | * For read-write operations, the container is converted to array, before the read operation, | + | * For read-write |
Emitting the following deprecation notice: < | Emitting the following deprecation notice: < | ||
Line 246: | Line 249: | ||
* Fetch operations will throw different errors depending on the fetch operation, //after// the type of the offset has been checked: | * Fetch operations will throw different errors depending on the fetch operation, //after// the type of the offset has been checked: | ||
- | | + | |
- | * For attempting to use the string offset as a container: < | + | * For attempting to use the string offset as a container: < |
- | * For attempting to use the string offset as an object: < | + | * For attempting to use the string offset as an object: < |
- | * For attempting to use increment or decrement the string offset: < | + | * For attempting to use increment or decrement the string offset: < |
Attempting to read a non initialized string offset emits the following warning: | Attempting to read a non initialized string offset emits the following warning: | ||
Line 512: | Line 515: | ||
* Fetch Append: the < | * Fetch Append: the < | ||
+ | |||
+ | * Increment/ | ||
Because < | Because < | ||
Line 605: | Line 610: | ||
$o = new T(); | $o = new T(); | ||
- | $a = new ArrayObject(); | ||
- | |||
$a = new ArrayObject($o); | $a = new ArrayObject($o); | ||
var_dump(isset($a[' | var_dump(isset($a[' | ||
Line 677: | Line 680: | ||
* Call method to verify the offset exists: | * Call method to verify the offset exists: | ||
- | | + | |
- | * Otherwise: call method to get value of offset: | + | * Otherwise: call method to get value of offset: |
- If the value is < | - If the value is < | ||
- Otherwise: return < | - Otherwise: return < | ||
Line 799: | Line 802: | ||
Cross-version compatible code can use DNF types to type their input arguments, e.g: | Cross-version compatible code can use DNF types to type their input arguments, e.g: | ||
<PHP> | <PHP> | ||
- | function foo(ArrayAccess|(DimensionReadable& | + | function foo(ArrayAccess|(DimensionFetchable& |
/* Do something useful */ | /* Do something useful */ | ||
} | } | ||
Line 882: | Line 885: | ||
and it cannot fulfill its role anymore with the new dimension handlers, | and it cannot fulfill its role anymore with the new dimension handlers, | ||
the struct is removed and alongside it the pointer to such a struct on the < | the struct is removed and alongside it the pointer to such a struct on the < | ||
+ | |||
+ | == Throw an Error when trying to increment or decrement an object offset == | ||
+ | |||
+ | Incrementing/ | ||
+ | whereas using < | ||
+ | and usually when acting on object properties this is what happens. | ||
+ | |||
+ | The current limitation is because we do not have sufficient specialized VM opcodes for this specific case. | ||
+ | Therefore, we propose to hard error, like we do for string offsets, so that if we do add the relevant opcodes we can | ||
+ | properly support the Read-Write behaviour. | ||
== Changes to ArrayObject == | == Changes to ArrayObject == | ||
Line 892: | Line 905: | ||
* Fix < | * Fix < | ||
* When using an object as a backing value: | * When using an object as a backing value: | ||
- | | + | |
- | * Emit dynamic properties warning when using an object as a backing value that does not allow dynamic properties | + | * Emit dynamic properties warning when using an object as a backing value that does not allow dynamic properties |
- | * Throw < | + | * Throw < |
- | * Throw < | + | * Throw < |
+ | * Throw < | ||
* Continue to ignore any < | * Continue to ignore any < | ||
Line 906: | Line 920: | ||
but it also " | but it also " | ||
- | Our solution is to add legacy dimension handlers to classes that implement | + | The solution |
- | reproducing the current behaviour | + | < |
+ | but also add legacy dimension handlers | ||
+ | such an object. | ||
However, if one of the new interfaces is implemented for dedicated support to appending, fetching, | However, if one of the new interfaces is implemented for dedicated support to appending, fetching, | ||
and fetch-appending, | and fetch-appending, | ||
Line 953: | Line 969: | ||
The < | The < | ||
type removed from the union type for the < | type removed from the union type for the < | ||
+ | |||
+ | Moreover, most code that expects resources as offsets already use an explicit < | ||
== Emit warnings for invalid offset types on arrays == | == Emit warnings for invalid offset types on arrays == | ||
Line 1034: | Line 1052: | ||
Promote all warnings to < | Promote all warnings to < | ||
+ | |||
+ | ===== Backward Incompatible Changes ===== | ||
+ | |||
+ | A recap of the BC breaking changes being introduced in PHP 8.4: | ||
+ | |||
+ | * New algorithm when calling < | ||
+ | * < | ||
+ | * Trying to read offsets of a < | ||
+ | * Leading numeric string used as an offset for strings would throw an < | ||
+ | * Float numeric strings (i.e. non integer-numeric strings) used as an offset for strings would now throw an < | ||
+ | * < | ||
+ | |||
+ | A recap of the new warnings being introduced in PHP 8.4: | ||
+ | |||
+ | * A warning when checking the existence of an offset on invalid container types (except for < | ||
+ | * A warning prior to reading an undefined offset when it is part of a read-write operation | ||
+ | * A warning is emitted when trying to use a value of type < | ||
+ | * A warning is emitted when trying to check the existence of string offset with invalid offset types | ||
+ | |||
+ | A recap of the deprecations being introduced in PHP 8.4: | ||
+ | |||
+ | * The < | ||
+ | * The < | ||
+ | * The < | ||
+ | |||
+ | For details on each of those, refer to their relevant sections. | ||
===== Version ===== | ===== Version ===== |
rfc/container-offset-behaviour.1720567795.txt.gz · Last modified: 2024/07/09 23:29 by girgias