[php-src] Issue #22738: Enums inside classes

From: Date: Wed, 15 Jul 2026 07:27:19 +0000
Subject: [php-src] Issue #22738: Enums inside classes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-252433@lists.php.net to get a copy of this message
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 ```

« previous php.bugs (#252433) next »