Using interfaces

Interfaces are useful tools for systems architects and are often used to prototype an Application Programming Interface (API). Interfaces don't contain actual code, but can contain names of methods as well as method signatures.

Note

All methods identified in the Interface have a visibility level of public.

How to do it...

  1. Methods identified by the interface cannot contain actual code implementations. You can, however, specify the data types of method arguments.
  2. In this example, ConnectionAwareInterface identifies a method, setConnection(), which requires an instance of Connection as an argument:
    interface ConnectionAwareInterface
    {
      public function setConnection(Connection $connection);
    }
  3. To use the interface, add the keyword implements ...

Get PHP 7: Real World Application Development 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.