Enums inside classes
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the proposal's examples and the existing PHP enum and class language rules. No source files or tests are identified, so the first step is to determine the syntax, visibility, and access semantics needed before drafting an RFC. Done means producing an agreed language-design proposal rather than a localized code change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100