php / php/php-src

Enums inside classes

オープン
#22,738 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Feature Status: Requires RFC
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

I wanted to briefly gauge the sentiment here regarding integrated enums in PHP classes, as a preliminary step toward an RFC. I think this would be quite concise.

Proposal: Enums should be embeddable in PHP classes. The goal is to avoid unnecessarily small files while keeping the namespace clean.

When classes work with many constants—perhaps even in groups—enums are a natural choice to define them and make them accessible for others:

public class Test {
    public const string PARAM_ONE = 'one';
    public const string PARAM_TWO = 'tow';
    //... more
    public const string CONST_ONE = 1;
    public const string CONST_TWO = 2;
        //... more
}

Instead of creating files just for the enums (autoloading), like TestParams.php and TestConsts.php, something like this would be nice, which would give them Enums a proper home, too:

public class Test {
    public enum PARAM {
        public const string ONE = 'one';
        public const string TWO = 'tow';
        //... more
    }
    public enum CONST {
        public const string CONST_ONE = 1;
        public const string CONST_TWO = 2;
        //... more
    }
}

The key question will be: how can the enums be made accessible? To avoid having different methods for internal and external access, general access with appropriate visibility would be the right approach:

Test::PARAM::One

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提案の例と、既存の PHP の enum およびクラスに関する言語規則を確認します。ソースファイルやテストは特定されていないため、最初のステップは RFC の草案を作成する前に、必要な構文、可視性、アクセスセマンティクスを明確にすることです。完了とは、ローカライズされたコード変更ではなく、合意された言語設計提案を作成することを意味します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
静か
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。