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 19:35] marandallrfc:undefined_property_error_promotion [2022/05/06 18:22] (current) marandall
Line 3: Line 3:
   * Date: 2022-04-04   * Date: 2022-04-04
   * Author: Mark Randall, marandall@php.net   * Author: Mark Randall, marandall@php.net
-  * Status: Under Discussion+  * Status: Accepted
  
 ===== Introduction ===== ===== Introduction =====
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.1649273740.txt.gz · Last modified: 2022/04/06 19:35 by marandall