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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
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

Pull Requests

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: Sat Dec 21 18:01:29 2024 UTC