MIR0709
InterfaceInstantiation
An interface is used with new to create an instance. Interfaces cannot be instantiated; only
concrete classes that implement the interface can be.
Example
Section titled “Example”<?phpinterface Serializable { public function serialize(): string;}
$obj = new Serializable(); // cannot instantiate interfaceHow to fix
Section titled “How to fix”Instantiate a concrete class that implements the interface instead:
<?phpclass JsonSerializable implements Serializable { public function serialize(): string { return '{}'; }}
$obj = new JsonSerializable();