Enum %s cannot include magic method %s

Description

Some magic methods are not allowed in an enumeration. __get, __set, __isset, __unset, __construct, __destruct, __sleep, __wakeup, __serialize, __unserialize, __toString, __set_state, __clone and __debugInfo.

This also means that some other magic methods are allowed : __call, __callStatic and __invoke.

Example

<?php

enum E {
    function __get($a) {}
}

?>

Literal Examples

  • Enum e cannot include magic method __get

  • Enum e cannot include magic method __set

  • Enum e cannot include magic method __destruct

Solutions

  • Remove the magic method from the enumeration.

  • Turn the enumeration into a class.

See Also