Enums inside classes
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C
- Sterne
- 40.4k
- Forks
- 8.1k
- Ø Merge
- 2 T. 13 Std.
- Gemergte PRs (30 T.)
- 96
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit der Prüfung der Beispiele des Vorschlags und der bestehenden Sprachregeln für PHP-Enums und -Klassen. Da keine Quelldateien oder Tests angegeben sind, besteht der erste Schritt darin, die erforderliche Syntax, Sichtbarkeit und Zugriffssemantik zu bestimmen, bevor ein RFC erstellt wird. Als erledigt gilt die Erstellung eines abgestimmten Sprachdesign-Vorschlags und nicht einer lokalisierten Codeänderung.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- php
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Ruhig
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100