rfc:undefined_property_error_promotion
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:undefined_property_error_promotion [2022/04/04 22:49] – marandall | rfc:undefined_property_error_promotion [2022/05/06 18:22] (current) – marandall | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Undefined Property Error Promotion ====== | ====== PHP RFC: Undefined Property Error Promotion ====== | ||
- | * Version: | + | * Version: |
- | * Date: 2023-04-04 | + | * Date: 2022-04-04 |
- | * Author: Mark Randall, marandall@php.com | + | * Author: Mark Randall, marandall@php.net |
- | * Status: | + | * Status: |
===== Introduction ===== | ===== Introduction ===== | ||
- | Undefined properties are those that have not yet been defined either by the presence of a property declaration, | + | Undefined properties are those that have not yet been defined either by the presence of a property declaration, |
- | Undefined properties previously triggered an E_NOTICE, however this was upgraded to E_WARNING as part of the PHP 8.0 Engine Warnings RFC: https:// | + | Undefined properties previously triggered an E_NOTICE, however this was upgraded to E_WARNING as part of the PHP 8.0 Engine Warnings RFC: https:// |
===== Proposal ===== | ===== Proposal ===== | ||
This RFC proposes that accessing an undefined property is rendered illegal behaviour in the next major version of PHP, and will result in an error exception being thrown if it occurs. | This RFC proposes that accessing an undefined property is rendered illegal behaviour in the next major version of PHP, and will result in an error exception being thrown if it occurs. | ||
- | For the purposes of this RFC, accessing an property means to use the property in such a way that the engine attempts to read its value for use in an expression, without accounting for the possibility of it being unset. These can be identified by the warning Undefined property < | + | For the purposes of this RFC, accessing an property means to use the property in such a way that the engine attempts to read its value for use in an expression, without accounting for the possibility of it being unset. These can be identified by the warning Undefined property < |
isset / empty / null coalesce DO account for undefined properties and as such are not covered by this RFC. | isset / empty / null coalesce DO account for undefined properties and as such are not covered by this RFC. | ||
+ | |||
+ | The presence of magical `get` will continue to work as it does now, and unknown properties will route to the magical `get` handler rather than cause an error (unless called within `get` on itself). | ||
===== Considerations ===== | ===== Considerations ===== | ||
Line 52: | Line 54: | ||
</ | </ | ||
- | There are several options to discuss: | + | To provide |
- | + | ||
- | - Leave undefined properties as they are | + | |
- | - Throw for accessing an undefined property unless AllowDynamicProperties has been set, but an E_WARNING would be emitted. | + | |
- | - Throw for accessing an undefined property unless AllowDynamicProperties has been set, but WITHOUT emitting a warning or notice. | + | |
- | - Throw for accessing any undefined property except for stdClass | + | |
- | - Throw for accessing any undefined property. | + | |
- | + | ||
- | Of these, the option with the most consistency is throwing for accessing any undefined property, and placing | + | |
- | + | ||
- | The use of AllowDynamicProperties to provide double-duty for read behaviour protection | + | |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | Accessing an undefined property will result in an Error exception being thrown. | + | Accessing an undefined property |
Line 75: | Line 67: | ||
A minor change will be included in the next minor version to alter the existing warning message to indicate the warning will become an error in 9.0. | A minor change will be included in the next minor version to alter the existing warning message to indicate the warning will become an error in 9.0. | ||
- | ===== Proposed | + | ===== Voting ===== |
- | Include these so readers know where you are heading and can discuss the proposed | + | |
+ | Voted started on 2022-04-22, ending 2022-05-05 | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | Meta vote: | ||
+ | |||
+ | <doodle title=" | ||
+ | * Backwards compatibility breaks | ||
+ | * Would be in favour, but not in 9.0 | ||
+ | * Do not like stdClass behaviour | ||
+ | * Something else | ||
+ | </ | ||
rfc/undefined_property_error_promotion.txt · Last modified: 2022/05/06 18:22 by marandall