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 interface %s

Description

An interface represents an abstract class, and cannot be instantiated alone. For that, the interface must be implemented by a class, aka, it must be specified with the implements keyword.

Example

<?php

interface I {}

//Cannot instantiate interface I
new I();

class XI implements I {
}

new XI(); 

?>

Literal Examples

  • Cannot instantiate interface i

Alternatives

  • Implement the interface with a class and use that class.