[php-src] Issue #12743: Automatically implements `Stringable` on backed Enum of type string

From: Date: Tue, 21 Nov 2023 11:13:21 +0000
Subject: [php-src] Issue #12743: Automatically implements `Stringable` on backed Enum of type string
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245856@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12743 Author: lyrixx ### Description ATM, we could write: ```php enum Foobar: string { case Foo = 'foo'; } ``` But every time we need the string value, we have to use ->value It could be nice to write: ```php enum Foobar: string { case Foo = 'foo'; public function __toString(): string { return $this->value; } } echo Foobar::Foo; ``` But this is forbidden ```console $ php test.php PHP Fatal error: Enum Foobar cannot include magic method __toString ``` --- So it would be awesome if PHP could implement the Stringable for use. So, the following code could work: ```php enum Foobar: string { case Foo = 'foo'; } echo Foobar::Foo; ```

« previous php.bugs (#245856) next »