rfc:typehint_array_desctructuring
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision |
rfc:typehint_array_desctructuring [2020/04/16 09:49] – created wol-soft | rfc:typehint_array_desctructuring [2020/04/16 11:43] – wol-soft |
---|
| |
===== Proposal ===== | ===== Proposal ===== |
This proposal adds the option to add type hints to array destructuring expressions. The type hints behave identically to the type hints processed for function calls (compare https://wiki.php.net/rfc/scalar_type_hints_v5). This includes a controllability of the behaviour using the strict_types directive: | This proposal adds a new syntax to add type hints to array destructuring expressions. The type hints behave identically to the type hints processed for function calls (compare https://wiki.php.net/rfc/scalar_type_hints_v5). This includes a controllability of the behaviour using the strict_types directive. Type checks will be executed during the assignment of the variables when resolving the array destructuring expression. The variables will **not** keep any information concerning the check (they will not behave like typed variables afterwards, just like type checks in method signatures). |
| |
<code php> | <code php> |
// ... | // ... |
} | } |
| </code> |
| |
| The for PHP 8.0 accepted union types (https://wiki.php.net/rfc/union_types_v2) will also be allowed: |
| |
| <code php> |
| [int|float $number, string $description] = [1.5, "One point five"] |
</code> | </code> |
| |
rfc/typehint_array_desctructuring.txt · Last modified: 2020/04/16 13:56 by wol-soft