[php-src] Issue #22738: Enums inside classes
[email protected] (procodix) Wed, 15 Jul 2026 07:27:19 +0000
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Issue: https://github.com/php/php-src/issues/22738
Author: procodix
### 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:
```php
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:
```php
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:
```php
Test::PARAM::One
```