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...
- Methods identified by the interface cannot contain actual code implementations. You can, however, specify the data types of method arguments.
- In this example,
ConnectionAwareInterface
identifies a method,setConnection()
, which requires an instance ofConnection
as an argument:interface ConnectionAwareInterface { public function setConnection(Connection $connection); }
- 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.