Casting An Enum Case¶
<?php
enum E: string {
case A = "ab";
}
(string) E::A;
TIL that enumeration cases cannot be cast. They can’t be to a boolean, because they are an object.
They can’t be cast to their scalar value (int or string), even though it looks reasonable to do.
Of course, they can be cast to array (they are simply put inside an array), or to an object (nothing happens).
See Also¶
Cannot Cast Enum [Try me]
PHP Error Messages¶
PHP Features¶
Last updated: 14 July 2026