php.net |  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
24 - 5 = ?
Subscribe to this entry?

 
 [2015-07-02 12:05 UTC] david dot proweb at gmail dot com
Description:
------------
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.

Currently:

    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.

    class_statement:
        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_PROTECTED
 +    | T_PRIVATE
 +    | T_FINAL;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-02 18:23 UTC] requinix@php.net
-Package: PHP Language Specification +Package: Class/Object related
 [2015-08-19 19:15 UTC] sean at siobud dot com
This is a duplicate of https://bugs.php.net/bug.php?id=27022
 [2015-08-19 19:21 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 07:01:28 2024 UTC