rfc:undefined_property_error_promotion

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:undefined_property_error_promotion [2022/04/04 23:24] marandallrfc: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: 0.9 +  * Version: 1 
-  * Date: 2023-04-04 +  * Date: 2022-04-04 
-  * Author: Mark Randall, marandall@php.com +  * Author: Mark Randall, marandall@php.net 
-  * Status: Draft+  * Status: Accepted
  
 ===== Introduction ===== ===== Introduction =====
-Undefined properties are those that have not yet been defined either by the presence of a property declaration, or by adding them to the properties table through direct assignment, or by having them assigned by an internal function such as json_decode. Accessing an undefined property emits an E_WARNING "Undefined property <className>:$varName" and treats the value as if it were null, but does not otherwise interupt execution, allowing code execution to continue unabated, but potentially in an unintended state.+Undefined properties are those that have not yet been defined either by the presence of a property declaration, or by adding them to the properties hashmap through direct assignment, or by having them assigned by an internal function such as json_decode. Accessing an undefined property emits an E_WARNING "Undefined property <className>::$varName" and treats the value as if it were null, but does not otherwise interupt execution, allowing code execution to continue unabated, but potentially in an unintended state.
  
 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://wiki.php.net/rfc/engine_warnings - By the time this RFC would come into effect, if passed, undefined properties would have emitted a warning for 5+ years. 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://wiki.php.net/rfc/engine_warnings - By the time this RFC would come into effect, if passed, undefined properties would have emitted a warning for 5+ years.
Line 13: Line 13:
 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 <className>:$varName.+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 <className>::$varName.
  
 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:
 </PHP> </PHP>
  
-There are several options to discuss: +To provide the most consistent handlingthis RFC proposes that stdClass will also throw an error if an undefined property is accessed.
- +
-  - 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 propertyand placing an expectation upon the programmer to use the existing undefined-aware language tools to check for a property being defined, before attempting to read it. +
- +
-The use of AllowDynamicProperties to provide double-duty for read behaviour protection is provided for the purposes of discussion, but is not the preferred option for this RFC+
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
-Accessing an undefined property will result in an Error exception being thrown.+Accessing an undefined property in a manner that currently results in an "undefined property" warning will in future result in an Error exception being thrown.
  
  
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 Choices ===== +===== Voting ===== 
-Include these so readers know where you are heading and can discuss the proposed voting options.+ 
 +Voted started on 2022-04-22, ending 2022-05-05 
 + 
 +<doodle title="Promote Undefined Property Access to Throw an Error?" auth="marandall" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
 + 
 +Meta vote: 
 + 
 +<doodle title="Main reason for voting against undefined_property_error_promotion if you did?" auth="marandall" voteType="single" closed="true"> 
 +   * Backwards compatibility breaks 
 +   * Would be in favour, but not in 9.
 +   * Do not like stdClass behaviour 
 +   * Something else 
 +</doodle>
  
rfc/undefined_property_error_promotion.1649114692.txt.gz · Last modified: 2022/04/04 23:24 by marandall