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/21 02:29] – Add link to upgrade tool 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.
  
-PHP 4 introduced the ''var'' keyword as the only means to declare class properties.+''var'' would remain a reserved word in PHP 8.0 for potential future usage.
  
-PHP 5 added the ''public''''protected'', and ''private'' keywords for declaring these properties with a certain visibility level To quote the documentation:+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.
  
-> "The PHP 4 method of declaring a variable with the ''var'' keyword [was] supported **for compatibility reasons** (as a synonym for the ''public'' keyword"+===== 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: 
 + 
 +> "The PHP 4 method of declaring a variable with the ''var'' keyword [was] supported **for compatibility reasons** (as a synonym for the ''public'' keyword)"
  
 (emphasis added) (emphasis added)
Line 19: 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 ====
-The primary reason for introducing this change is to eliminate duplicate functionality in the language.  Both ''var'' and ''public'' work identically, so do we really need two different keywords which do exactly the same thing?+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).
  
-==== Low Usage ==== +==== ''public'' Is More Useful ==== 
-Of the top X,000 packages on Packagist, only X use ''var'', thus confirming that its usage is relatively low.  This means fewer people will be impacted by this change.+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 ==== ==== Removes Legacy Functionality ====
Line 34: Line 61:
 ''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. ''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 removingother legacy features with modern equivalents in major releases:+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_php4_constructors|PHP 4 constructors were removed in 7.0]]
Line 40: Line 67:
   * [[rfc:remove_deprecated_functionality_in_php7|Several other previously-deprecated features were removed in 7.0]]   * [[rfc:remove_deprecated_functionality_in_php7|Several other previously-deprecated features were removed in 7.0]]
  
-==== Ample Warning ==== +==== Low Usage ==== 
-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.+The top 10,000 packages on Packagist were analyzed (along with their dependencies) to determine the proliferation of ''var'' in the PHP ecosystem:
  
-==== Easy Upgrade Path ==== +^ % ^ Description  ^  Number of Packages ^ 
-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.+|   62% | Use ''public'' only |  6,221 | 
 +|   27% | Don't use public variables of any kind |  2,665 | 
 +|   4% | Use ''var'' internally |  448 | 
 +|   4% | Have a dependency which uses ''var'' |  352 | 
 +|   //3%// | //Failed to be analyzed due to misc. errors in the survey tool// |  //335// | 
 + 
 +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) 
 +  * 6%   - ''var'' (98,745 instances) 
 + 
 +The following packages are the "worst offenders", making up 62% of the total number of ''var'' keywords found: 
 + 
 +  * 22% - simpletest (22,116 instances) 
 +  * 17% - phpseclib (16,648 instances) 
 +  * 14% - mpdf (14,000 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.
  
 ===== Cons ===== ===== Cons =====
  
 ==== It's Not Broken ==== ==== It's Not Broken ====
-There are no technical issues with the current implementation of varand therefore no strong need to remove it.+There are no technical issues with the current implementation of ''var'' and therefore no urgency to remove it.
  
 ==== Breaks Backwards Compatibility ==== ==== Breaks Backwards Compatibility ====
Line 56: Line 105:
  
 ==== No Functionality Benefit ==== ==== No Functionality Benefit ====
-This change does not introduce any new functionality or other benefit 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 64: Line 116:
  
 ===== Upgrade Tool ===== ===== Upgrade Tool =====
-An [[https://gist.github.com/colinodell/5fb5e5d474674f294a38|upgrade tool]] is provided which 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 75: Line 127:
 ==== To Opcache ==== ==== To Opcache ====
 ? ?
- 
-===== Unaffected PHP Functionality ===== 
-Classes which only use the PHP 5 style keywords for declaring properties (''public'', ''protected'', and ''private'') would be unaffected. 
  
 ===== Future Scope ===== ===== Future Scope =====
-Reserving the ''var'' keyword may 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
 + 
 +===== 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)**.
  
-===== Proposed Voting Choices ===== 
 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.+  * [[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.1456021751.txt.gz · Last modified: 2017/09/22 13:28 (external edit)