CHAPTER 14

image

Interface

An interface specifies methods that classes using the interface must implement. They are defined with the interface keyword followed by a name and a code block. Their naming convention is to start with a small “i” and then to have each word initially capitalized.

interface iMyInterface {}

Interface signatures

The code block for an interface can contain signatures for instance methods. These methods cannot have any implementations. Instead, their bodies are replaced by semicolons. Interface methods must always be public.

interface iMyInterface{  public function myMethod();}

Additionally, interfaces may define constants. These ...

Get PHP Quick Scripting Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.