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/06 17:57] 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: 2022-04-04   * Date: 2022-04-04
   * Author: Mark Randall, marandall@php.net   * Author: Mark Randall, marandall@php.net
-  * Status: Draft+  * Status: Accepted
  
 ===== Introduction ===== ===== Introduction =====
Line 17: Line 17:
 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 __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).+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 49: Line 49:
  
 <PHP> <PHP>
-if (!empty($obj->name)) { +if (isset($obj->name)) { 
   echo "Hello " . $obj->name;   echo "Hello " . $obj->name;
 } }
 </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 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 propertyincluding stdClass, and 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.+
  
 ===== 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 73: 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 ===== 
-TBD+ 
 +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.0 
 +   * Do not like stdClass behaviour 
 +   * Something else 
 +</doodle>
  
rfc/undefined_property_error_promotion.1649267846.txt.gz · Last modified: 2022/04/06 17:57 by marandall