O'Reilly logo

PHP 7 Programming Cookbook by Doug Bierer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required