rfc:undefined_variable_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_variable_error_promotion [2022/02/24 10:36] marandallrfc:undefined_variable_error_promotion [2022/03/28 17:52] (current) marandall
Line 3: Line 3:
   * Date: 2022-02-17   * Date: 2022-02-17
   * Author: Mark Randall marandall@php.net   * Author: Mark Randall marandall@php.net
-  * Status: Under Discussion+  * Status: Accepted
   * Target: PHP 9.0   * Target: PHP 9.0
   * First Published at: https://wiki.php.net/rfc/undefined_variable_error_promotion   * First Published at: https://wiki.php.net/rfc/undefined_variable_error_promotion
Line 10: Line 10:
 Undefined variables are those that have not yet been initialised with a value prior to being read. Accessing an undefined variable currently emits an E_WARNING "Warning: Undefined variable $varname" and treats the variable as if it were a null, but does not otherwise interrupt execution, allowing code execution to continue unabated, but likely in an unintended state. Undefined variables are those that have not yet been initialised with a value prior to being read. Accessing an undefined variable currently emits an E_WARNING "Warning: Undefined variable $varname" and treats the variable as if it were a null, but does not otherwise interrupt execution, allowing code execution to continue unabated, but likely in an unintended state.
  
-Although a custom error handler can already be used to raise an Error exception, this requires additional userland code to configure, when instead we should be aiming to provide a safer experience by default. The need to support calling a custom error handler does itself also introduce additional complexity into the engine, leading  to "increasingly complex games" to keep it working.+Although a custom error handler can already be used to raise an Error exception, this requires additional userland code to configure, when instead we should be aiming to provide a safer experience by default. The need to support calling a custom error handler does itself also introduce additional complexity into the engine, leading  to "increasingly complex games" to keep it working (see "Benefits"). 
 + 
 +**RFC History / Previous Votes**
  
 This change was last discussed during the Engine Warnings RFC (https://wiki.php.net/rfc/engine_warnings) where it received 56% in favour of making this behaviour an Error exception. It is likely that the only reason this vote failed to reach a supermajority at the time was because the condition was previously a notice, and some felt the jump from notice to error was too great for one version. Accessing undefined variables will have been a warning for 5+ years by the time this RFC would come into effect. This change was last discussed during the Engine Warnings RFC (https://wiki.php.net/rfc/engine_warnings) where it received 56% in favour of making this behaviour an Error exception. It is likely that the only reason this vote failed to reach a supermajority at the time was because the condition was previously a notice, and some felt the jump from notice to error was too great for one version. Accessing undefined variables will have been a warning for 5+ years by the time this RFC would come into effect.
Line 126: Line 128:
 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 ===== + 
-Yes / No to promote to Error.+===== Unaffected Functionality ===== 
 +If the code does not currently emit a "Warning: Undefined variable $varname" then it is out of scope for this RFC. This RFC does NOT apply to array indexes. 
 + 
 +===== Vote ===== 
 +Vote opened 2022-03-14, vote closes 2022-03-28 
 + 
 +<doodle title="Promote Undefined Variables to Throw an Error" auth="marandall" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
 + 
 +Meta vote for reasoning of voting against: 
 + 
 +<doodle title="Main reason for voting against if you did?" auth="marandall" voteType="single" closed="true"> 
 +   * Using undefined variables is a legitimate coding style 
 +   * Backwards compatibility breaks 
 +   * Would be in favour, but not in 9.
 +   * Something else 
 +</doodle>
  
 ===== References ===== ===== References =====
rfc/undefined_variable_error_promotion.1645698969.txt.gz · Last modified: 2022/02/24 10:36 by marandall