Skip to content

MIR0719

EnumInstantiation

An enum is used with new. Enum instances are its cases; PHP throws Cannot instantiate enum for new Suit(), also for new self() or new static() inside the enum.

<?php
enum Suit {
case Hearts;
case Spades;
}
$suit = new Suit(); // cannot instantiate enum

Use a case, or look one up by value on a backed enum:

<?php
$suit = Suit::Hearts;