|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #69980 Support to private/protected const on classes
Submitted: 2015-07-02 12:05 UTC Modified: 2015-08-19 19:21 UTC
From: david dot proweb at gmail dot com Assigned:
Status: Duplicate Package: Class/Object related
PHP Version: 7.0.0alpha2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: david dot proweb at gmail dot com
New email:
PHP Version: OS:


 [2015-07-02 12:05 UTC] david dot proweb at gmail dot com
Currently, const defined in classes are always public. I suggest allow private/protected it. It'll allow I define my own private/protected constants inside my class, without need create a static private/protected property to store this kind of data.


    class Test 
        private static $VERSION_MATCH = '/^\d+\.\d+$/';
        public static function match($version) 
            return preg_match(self::$VERSION_MATCH, $version);

After implementation:

    class Test 
        private const VERSION_MATCH = '/^\d+\.\d+$/';
        public static function match($version) 
            return preg_match(self::VERSION_MATCH, $version);

Imagine that I don't want that this const be public.

        variable_modifiers property_list ';'
 ~    | class_member_modifier T_CONST class_const_list ';'
      | T_USE name_list trait_adaptations
      | method_modifiers function returns_ref identifier '(' parameter_list ')'
            return_type backup_doc_comment method_body;

 +  class_member_modifier:
 +      /* empty */
 +    | T_PUBLIC
 +    | T_PRIVATE
 +    | T_FINAL;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-02 18:23 UTC]
-Package: PHP Language Specification +Package: Class/Object related
 [2015-08-19 19:15 UTC] sean at siobud dot com
This is a duplicate of
 [2015-08-19 19:21 UTC]
-Status: Open +Status: Duplicate
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 02 02:05:53 2022 UTC