Differences from objects

Although Enums are built on classes and objects, they do not support all object-related functionality. In particular, Enum cases are forbidden from having state.

The following object functionality is available, and behaves just as it does on any other object:

The ::class magic constant on an Enum type evaluates to the type name including any namespace, exactly the same as an object. The ::class magic constant on a Case instance also evaluates to the Enum type, as it is an instance of that type.

Additionally, enum cases may not be instantiated directly with new, nor with ReflectionClass::newInstanceWithoutConstructor() in reflection. Both will result in an error.

<?php$clovers = new Suit();// Error: Cannot instantiate enum Suit$horseshoes = (new ReflectionClass(Suit::class))->newInstanceWithoutConstructor()// Error: Cannot instantiate enum Suit?>