rfc:class_const_visibility

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
rfc:class_const_visibility [2015/03/02 08:45] – created reezerfc:class_const_visibility [2015/12/08 16:01] – Merged into 7.1 sean-der
Line 1: Line 1:
 ====== PHP RFC: Support Class Constant Visibility ====== ====== PHP RFC: Support Class Constant Visibility ======
-  * Version: 0.1 +  * Version: 0.2 
-  * Date: 2015-03-02 +  * Date: 2015-09-13 
-  * Author: Reeze Xiareeze@php.net +  * Author: Sean DuBois <sean@siobud.com>, Reeze Xia <reeze@php.net> 
-  * Status: Draft+  * Status: Accepted
   * First Published at: http://wiki.php.net/rfc/class_const_visibility   * First Published at: http://wiki.php.net/rfc/class_const_visibility
  
-This is a suggested template for PHP Request for Comments (RFCs). Change this template to suit your RFC.  Not all RFCs need to be tightly specified.  Not all RFCs need all the sections below. 
-Read https://wiki.php.net/rfc/howto carefully! 
  
 +===== Introduction =====
  
-Quoting [[http://news.php.net/php.internals/71525|Rasmus]]:+Classes in PHP allow modifiers on properties and methods, but not constants. 
 +It is an easily fixed inconsistency, and a feature that many want and most surprised 
 +that it doesn't already exist.  [[http://stackoverflow.com/questions/5339456/php-class-constant-visibility|Stack Overflow Thread]]
  
-> PHP is and should remain: +In thread on php-internals couple real world examples were offered. 
-> 1) pragmatic web-focused language +    * Defining bitmasks/magic numbers, but not exposing them globally. Before constants would be exposed allowing callers to depend on them. 
-> 2) loosely typed language +    * Help make it more clear what is important, exposing harmless constants clutters documentation  needlessly. 
-> 3) a language which caters to the skill-levels and platforms of a wide range of users+
  
-Your RFC should move PHP forward following his vision. As [[http://news.php.net/php.internals/66065|said by Zeev Suraski]] "Consider only features which have significant traction to a +===== Proposal =====
-large chunk of our userbase, and not something that could be useful in some +
-extremely specialized edge cases [...] Make sure you think about the full context, the huge audience out there, the consequences of  making the learning curve steeper with +
-every new feature, and the scope of the goodness that those new features bring."+
  
-===== Introduction ===== +This RFC propose PHP support class constant visibility that mirror the behavior of method 
-The elevator pitch for the RFC. The first paragraph in this section will be slightly larger to give it emphasis; please write a good introduction.+and property visibility
  
-===== Proposal ===== +Class constant may be define as public, private or protected. class constants declared 
-All the features and examples of the proposal.+without any explicit visibility keyword are defined as public
  
-To [[http://news.php.net/php.internals/66051|paraphrase Zeev Suraski]]explain hows the proposal brings substantial value to be considered +Proposed syntax: 
-for inclusion in one of the world's most popular programming languages.+ 
 +<code php> 
 +<?php 
 + 
 +class Token { 
 + // Constants default to public 
 + const PUBLIC_CONST = 0; 
 + 
 +        // Constants then also can have a defined visibility 
 +        private const PRIVATE_CONST = 0; 
 +        protected const PROTECTED_CONST = 0; 
 +        public const PUBLIC_CONST_TWO = 0; 
 +         
 +        //Constants can only have one visibility declaration list 
 +        private const FOO = 1BAR = 2; 
 +
 + 
 + 
 +//Interfaces only support public consts, and a compile time error will be thrown for anything else. Mirroring the behavior of methods. 
 +interface ICache { 
 +        public const PUBLIC = 0; 
 +        const IMPLICIT_PUBLIC = 1; 
 +
 + 
 +//Reflection was enhanced to allow fetching more than just the values of constants 
 +class testClass 
 +  const TEST_CONST = 'test'; 
 +
 + 
 +$obj = new ReflectionClass( "testClass" ); 
 +$const = $obj->getReflectionConstant( "TEST_CONST" ); 
 +$consts = $obj->getReflectionConstants(); 
 + 
 +</code>
  
-Remember that the RFC contents should be easily reusable in the PHP Documentation. 
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
-What breaks, and what is the justification for it? 
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
-List the proposed PHP versions that the feature will be included in.  Use relative versions such as "next PHP 5.x" or "next PHP 5.x.y".+ 
 +This RFC targets PHP 7.1
  
 ===== RFC Impact ===== ===== RFC Impact =====
 +
 ==== To SAPIs ==== ==== To SAPIs ====
-Describe the impact to CLI, Development web server, embedded PHP etc.+ 
 +None.
  
 ==== To Existing Extensions ==== ==== To Existing Extensions ====
-Will existing extensions be affected? 
  
-==== To Opcache ==== +None, all the class constant APIs will be the same. 
-It is necessary to develop RFC's with opcache in mind, since opcache is a core extension distributed with PHP.+There will be new _ex APIs that allow callers to explicitly pass flags.
  
-Please explain how you have verified your RFC's compatibility with opcache.+If a extension accesses non-public structures (the now non-existent class_constants HashTable) there will be breakage
  
-==== New Constants ==== +==== To Opcache ====
-Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation.+
  
-==== php.ini Defaults ==== +Need update.
-If there are any php.ini settings then list: +
-  * hardcoded default values +
-  * php.ini-development values +
-  * php.ini-production values+
  
-===== Open Issues ===== +===== Vote =====
-Make sure there are no open issues when the vote starts!+
  
-===== Unaffected PHP Functionality ===== +Simple Yes/No option. This requires a 2/3  majority.
-List existing areas/features of PHP that will not be changed by the RFC.+
  
-This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise.+This vote will close on 06:00 UTC on Tuesday 2015-10-27
  
-===== Future Scope ===== +<doodle title="Class Constant Visibility" auth="sdubois" voteType="single" closed="true"> 
-This sections details areas where the feature might be improved in future, but that are not currently proposed in this RFC. +   * Yes 
- +   * No 
-===== Proposed Voting Choices ===== +</doodle>
-Include these so readers know where you are heading and can discuss the proposed voting options. +
- +
-State whether this project requires a 2/3 or 50%+1 majority (see [[voting]])+
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
-Links to any external patches and tests go here. 
  
-If there is no patchmake it clear who will create a patchor whether a volunteer to help with implementation is needed.+A pull request has been made. It is feature complete but needs reviewmore testsand help with opcache changes : https://github.com/php/php-src/pull/1494
  
-Make it clear if the patch is intended to be the final patch, or is just a prototype. +This feature was merged into PHP master here: https://github.com/php/php-src/commit/a75c195000b3226904103244fa9c3d0ce1111838
- +
-===== Implementation ===== +
-After the project is implemented, this section should contain  +
-  - the version(s) it was merged to +
-  a link to the git commit(s) +
-  - a link to the PHP manual entry for the feature+
  
 ===== References ===== ===== References =====
-Links to external references, discussions or RFCs+  * http://php.net/manual/en/language.oop5.constants.php 
 +  * http://php.net/manual/en/language.oop5.visibility.php 
 + 
 +===== Changelog =====
  
-===== Rejected Features ===== +  * V0.1 Initial version 
-Keep this updated with features that were discussed on the mail lists.+  * V0.2 Adopted by Sean DuBois <sean@siobud.com>
rfc/class_const_visibility.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1