rfc:var_deprecation

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:var_deprecation [2016/02/23 00:59] – Added initial survey results colinodellrfc:var_deprecation [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== PHP RFC: "var" Deprecation ====== ====== PHP RFC: "var" Deprecation ======
-  * Date: 2016-02-20+  * Date: 2016-03-10
   * Author: Colin O'Dell <colinodell@php.net>   * Author: Colin O'Dell <colinodell@php.net>
-  * Status: Draft +  * Status: Declined 
-  * Discussion: http://markmail.org/message/wn3ykdwgplfctho7+  * Discussion: http://markmail.org/message/523vpfo2q5dwqyed
  
 ===== Introduction ===== ===== Introduction =====
  
-''var'' is currently a simple alias for ''public''.  Both keywords provide identical functionality.  This RFC therefore proposes the deprecation of ''var'' in favor of ''public''.+This RFC proposes that ''var'' be deprecated in PHP 7.1 (in favor of ''public'') and its functionality removed in PHP 8.0. 
 + 
 +''var'' would remain a reserved word in PHP 8.0 for potential future usage. 
 + 
 +An [[https://gist.github.com/colinodell/5fb5e5d474674f294a38|upgrade tool]] is provided to automatically replace all instances of ''var'' with ''public'' Code modified with this tool would be fully compatible with PHP 5, 7, and 8. 
 + 
 +===== Background ===== 
 + 
 +''var'' is currently a simple alias for ''public''.  However, ''public'' provides more functionality than the limited subset that ''var'' supports.  Because ''var'' only offers a duplicate yet limited subset of functionality, this RFC proposes the deprecation of ''var'' in favor of ''public''.
  
 PHP 4 introduced the ''var'' keyword as the only means to declare class properties.  Later on PHP 5 added the ''public'', ''protected'', and ''private'' keywords for declaring these properties with a certain visibility level.  To quote the documentation: PHP 4 introduced the ''var'' keyword as the only means to declare class properties.  Later on PHP 5 added the ''public'', ''protected'', and ''private'' keywords for declaring these properties with a certain visibility level.  To quote the documentation:
Line 17: Line 25:
 This alias was left intact for PHP 7. This alias was left intact for PHP 7.
  
-===== Proposal ===== +''public'', ''protected'', and ''private'' can also be used to declare static members and [[rfc:class_const_visibility|constants (coming in PHP 7.1)]] whereas ''var'' cannot.
-This RFC proposes that ''var'' be deprecated in PHP 7.1 and its functionality removed in PHP 8.0. +
- +
-''var'' would remain a reserved word in PHP 8.0 for potential future usage.+
  
 ===== Pros ===== ===== Pros =====
  
 ==== Removes Duplication ==== ==== Removes Duplication ====
-This will eliminate duplicate functionality in the language.  Both ''var'' and ''public'' behave identically and therefore both are not technically needed (other than for backwards-compatibility).+This will eliminate duplicate functionality in the language.  Both ''var'' and ''public'' behave identically for non-static member variables and therefore both are not technically needed (other than for backwards-compatibility). 
 + 
 +==== ''public'' Is More Useful ==== 
 +The only functional difference between ''var'' and ''public'' is that the latter also supports static members and [[rfc:class_const_visibility|constants (coming in PHP 7.1)]]: 
 + 
 +<code php> 
 +<?php 
 +class Example 
 +
 +    public $foo;        // Works 
 +    public static $foo; // Works 
 +    public const FOO    // Works 
 +     
 +    var $foo;           // Works 
 +    var static $foo;    // Doesn't work 
 +    var const FOO;      // Doesn't work 
 +
 +</code> 
 + 
 +''var'' is therefore a limited subset of ''public''
 + 
 +==== Ample Warning ==== 
 +PHP 8.0 is likely several years away.  Deprecating this now (rather than later) would provide developers with sufficient notice that their code may need to be modified to work on 8.0. 
 + 
 +==== Easy Upgrade Path ==== 
 +Because ''var'' is currently an alias for ''public'', updating older code is as simple as replacing ''var'' with ''public'' everywhere it appears.  A [[https://gist.github.com/colinodell/5fb5e5d474674f294a38|utility script]] has been provided with this RFC to aid with the transition. 
 + 
 +==== Removes Legacy Functionality ==== 
 + 
 +''var'' is a legacy feature from PHP 4 which has been superseded by the visibility keywords.  It was kept in PHP 5+ for backwards-compatibility.  Removing it would help clean up the lesser-used legacy bits of the language. 
 + 
 +There is precedent for deprecating and eventually removing other legacy features (with modern equivalents) as part of major releases: 
 + 
 +  * [[rfc:remove_php4_constructors|PHP 4 constructors were removed in 7.0]] 
 +  * [[rfc:remove_alternative_php_tags|Alternative PHP tags were removed in 7.0]] 
 +  * [[rfc:remove_deprecated_functionality_in_php7|Several other previously-deprecated features were removed in 7.0]]
  
 ==== Low Usage ==== ==== Low Usage ====
Line 37: Line 77:
 |   //3%// | //Failed to be analyzed due to misc. errors in the survey tool// |  //335// | |   //3%// | //Failed to be analyzed due to misc. errors in the survey tool// |  //335// |
  
-The total number of ''public'' and ''var'' keywords were counted across every file of every package (including dependencies):+Because dependencies may have already been counted as "packages using ''var'' internally", the true utilization is somewhere between 4 and 8%. 
 + 
 +The total number of ''public'' and ''var'' keywords were counted across every file of every package (including dependencies which may be counted multiple times):
  
   * 94% - ''public'' (1,650,084 instances)   * 94% - ''public'' (1,650,084 instances)
Line 48: Line 90:
   * 14% - mpdf (14,000 instances)   * 14% - mpdf (14,000 instances)
   * 9%  - simplepie (8,745 instances)   * 9%  - simplepie (8,745 instances)
 +
 +Updating these packages would drop overall ''var'' utilization to 1.5 - 3.0%.
  
 This survey confirms that modern PHP development has largely moved away from ''var'' Accepting this RFC will therefore have minimal impact on the ecosystem. This survey confirms that modern PHP development has largely moved away from ''var'' Accepting this RFC will therefore have minimal impact on the ecosystem.
- 
-==== Removes Legacy Functionality ==== 
- 
-''var'' is a legacy feature from PHP 4 which has been superseded by the visibility keywords.  It was kept in PHP 5+ for backwards-compatibility.  Removing it would help clean up the lesser-used legacy bits of the language. 
- 
-There is precedent for deprecating and eventually removing other legacy features (with modern equivalents) as part of major releases: 
- 
-  * [[rfc:remove_php4_constructors|PHP 4 constructors were removed in 7.0]] 
-  * [[rfc:remove_alternative_php_tags|Alternative PHP tags were removed in 7.0]] 
-  * [[rfc:remove_deprecated_functionality_in_php7|Several other previously-deprecated features were removed in 7.0]] 
- 
-==== Ample Warning ==== 
-PHP 8.0 is at least a few years away.  Deprecating this now (rather than later) would provide developers with sufficient notice that their code may need to be modified to work on 8.0. 
- 
-==== Easy Upgrade Path ==== 
-Because ''var'' is currently an alias for ''public'', updating older code is as simple as replacing ''var'' with ''public'' everywhere it appears.  A [[https://gist.github.com/colinodell/5fb5e5d474674f294a38|utility script]] has been provided with this RFC to aid with the transition. 
  
 ===== Cons ===== ===== Cons =====
Line 78: Line 106:
 ==== No Functionality Benefit ==== ==== No Functionality Benefit ====
 This change does not introduce any new functionality for developers.  Those who are not using ''var'' will see no impact.  Those who do use ''var'' will need to update their code. This change does not introduce any new functionality for developers.  Those who are not using ''var'' will see no impact.  Those who do use ''var'' will need to update their code.
 +
 +==== ''public'' Is Not The Same ====
 +Some developers do not feel comfortable replacing ''var'' with ''public'' because they did not intend for those variables to explicitly be public.  Although replacing ''var'' with ''public'' does result in the same functionality, it may unintentionally imply that those variables were explicitly intended to be public (which may not be the case).
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 85: Line 116:
  
 ===== Upgrade Tool ===== ===== Upgrade Tool =====
-An [[https://gist.github.com/colinodell/5fb5e5d474674f294a38|upgrade tool]] is provided which automatically replaces all instances of ''var'' with ''public''.+An [[https://gist.github.com/colinodell/5fb5e5d474674f294a38|upgrade tool]] is provided which automatically replaces all instances of ''var'' with ''public''.  Code modified with this tool should be fully-compatible with PHP 5, 7, and 8.
  
 ===== RFC Impact ===== ===== RFC Impact =====
 ==== To SAPIs ==== ==== To SAPIs ====
-?+None
  
 ==== To Existing Extensions ==== ==== To Existing Extensions ====
Line 100: Line 131:
 Reserving the ''var'' keyword will allow it to be used for new functionality in 8.0 and beyond. Reserving the ''var'' keyword will allow it to be used for new functionality in 8.0 and beyond.
  
-===== Proposed Voting Choices =====+===== Vote ===== 
 +The vote is a simple Yes/No on **whether to deprecate ''var'' in PHP 7.1 and remove its functionality from 8.0 (but reserve the keyword for future usage)**. 
 As this is a language change, this RFC requires a 2/3 majority to pass. As this is a language change, this RFC requires a 2/3 majority to pass.
 +
 +Voting started on 2016-03-24 and will end on 2016-03-31 at 12:30 UTC.
 +
 +<doodle title="Deprecate `var` in 7.1 and remove it from 8.0?" auth="colinodell" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
-No patch has been created yet Assistance would be greatly appreciated.+  * [[https://github.com/php/php-src/compare/master...tpunt:deprecate-var]] (Created by Thomas Punt)
  
 ===== References ===== ===== References =====
-  * [[Mailing list discussion|http://markmail.org/message/wn3ykdwgplfctho7]]+  * [[http://markmail.org/message/523vpfo2q5dwqyed|Official discussion thread]] 
 +  * [[http://markmail.org/message/wn3ykdwgplfctho7|Pre-draft mailing list discussion]] 
 +  * [[https://www.reddit.com/r/PHP/comments/49uer7/rfc_deprecating_var_in_favor_of_public/|Reddit discussion]]
rfc/var_deprecation.1456189177.txt.gz · Last modified: 2017/09/22 13:28 (external edit)