| alcaeus | Yes | 2026-04-07 10:01 |
| alexandredaubois | Abstain | 2026-04-08 12:10 |
| ashnazg | Yes | 2026-04-08 14:06 |
| beberlei | Yes | 2026-04-02 17:57 |
| bwoebi | Yes | 2026-04-03 01:58 |
| crell | Yes | 2026-04-06 17:20 |
| daniels | Yes | 2026-04-02 17:02 |
| derick | Yes | 2026-04-07 14:35 |
| galvao | Yes | 2026-04-09 11:03 |
| ilutov | Abstain | 2026-04-02 18:00 |
| kalle | No | 2026-04-02 21:31 |
| kguest | Yes | 2026-04-10 09:50 |
| klaussilveira | Yes | 2026-04-16 12:29 |
| mbeccati | Abstain | 2026-04-09 14:01 |
| narf | Yes | 2026-04-09 19:09 |
| ocramius | No | 2026-04-02 17:07 |
| pmjones | Yes | 2026-04-03 14:00 |
| ralphschindler | Yes | 2026-04-12 22:40 |
| ramsey | Yes | 2026-04-04 06:48 |
| shivam | Yes | 2026-04-11 19:44 |
| theodorejb | Abstain | 2026-04-05 14:06 |
| thorstenr | Yes | 2026-04-10 06:43 |
| timwolla | Abstain | 2026-04-02 17:53 |
Copied from wiki.php.net, last synchronized Oct 13, 2026 11:50 UTC
Enumerations (enums) were introduced in PHP 8.1 (enumerations). The RFC specified that magic methods other than __call(), __callStatic(), and __invoke() would not be permitted in enums, noting that most other magic methods involve state, which enum instances do not have. However, the exclusion also applies to __debugInfo(), which does not need to involve state. This RFC proposes allowing the __debugInfo() magic method on enums.
<?php
enum Foo: string {
case Bar = "Baz";
public function __debugInfo() {
return [__CLASS__ . '::' . $this->name . ' = ' . $this->value];
}
}
var_dump(Foo::Bar);
?>
produces the output
enum(Foo::Bar) (1) {
[0]=>
string(14) "Foo::Bar = Baz"
}
The error when trying to implement __debugInfo() on an enumeration is removed. The default validation of that magic method (visibility, arguments, return type) is applied if the method is present.
Simple example for a unit enum:
<?php
enum Foo {
case Bar;
public function __debugInfo() {
return [$this->name . ' is a case of the ' . __CLASS__ . ' enum'];
}
}
var_dump(Foo::Bar);
?>
produces the output
enum(Foo::Bar) (1) {
[0]=>
string(29) "Bar is a case of the Foo enum"
}
Simple example for a backed enum:
<?php
enum Foo: string {
case Bar = "Baz";
public function __debugInfo() {
return [__CLASS__ . '::' . $this->name . ' = ' . $this->value];
}
}
var_dump(Foo::Bar);
?>
produces the output
enum(Foo::Bar) (1) {
[0]=>
string(14) "Foo::Bar = Baz"
}
There should be no backward incompatible changes - this is the removal of an existing error.
Next PHP version (PHP 8.6).
Analysis tools that warn about trying to define a __debugInfo() method on enums would need to be updated to not warn when the code is for PHP 8.6+.
There are some built-in enums, e.g. \Random\IntervalBoundary - in the future, they may have __debugInfo() methods, but this RFC does not include such additions.
Perhaps some of the other magic methods should also be allowed.
Primary Vote requiring a 2/3 majority to accept the RFC:
Vote: Allow __debugInfo() in enums? — Yes: 16 · No: 2 · Abstain: 5 (closed)
https://github.com/php/php-src/pull/21425
After the RFC is implemented, this section should contain:
Links to external references, discussions, or RFCs.
__toString() on enums, rather than __debugInfo(), but feedback on the mailing list (https://news-web.php.net/php.internals/129540) led to a rewrite.If there are major changes to the initial proposal, please include a short summary with a date or a link to the mailing list announcement here, as not everyone has access to the wikis' version history.
__toString() version could be considered v0.1)enum(Foo::Bar) headers in the output, updated examples here to show the full output, minor editorial changes