Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cannot instantiate enum %s

Description

Enumeration cannot be instantiated directly.

An enumeration object is created automatically when reading one of its case.

Example

<?php

enum E {
	case A;
}

//Cannot instantiate enum E
new E();

// E
print get_class(E::A);

?>

Literal Examples

  • Cannot instantiate enum e

Alternatives

  • Use one of the enumeration cases.