HomePHP User-defined Interfaces in PHP 5: Introduction to Core Concepts
User-defined Interfaces in PHP 5: Introduction to Core Concepts
PHP5 takes users increasingly in the direction of object-oriented programming. The Standard PHP Library (SPL) is a new item that helps developers both with the creation of OOP applications and the maintenance of standardization. The SPL enables developers to work with user-defined interfaces. In this article, the first of a series, Alejandro Gervasio uses examples to introduce you to working with these interfaces, which can keep you from having to reinvent the wheel with each new project.
With the release of PHP5, a strong effort has been made to improve the existing Object Model available in previous versions of PHP. Taking PHP into the context of object-oriented programming was certainly a controversial topic, and very often the subject of many heated discussions. One recurring theme was the absence of relevant OOP features, available from long mature object-oriented languages such as Java or C++.
In response to that, PHP5 brought in a wealth of brand new features, designed specifically to provide programmers with the capacity to develop more robust OOP applications, while maintaining a strong sense of standardization, particularly with the introduction of the Standard PHP Library (SPL) within the PHP5 core distribution.
If you’ve already experienced the capabilities of PHP5, then you’re probably pretty familiar with the use of several PHP built-in interfaces such as “Iterator”, “IteratorAggregate” or “ArrayAccess” (to name the most popular ones) and some useful proprietary classes, like “ArrayIterator” or “ArrayObject”, aimed at solving standard problems.
Aside from this impressive set of built-in features included within the SPL, PHP5 offers the possibility of working with user-defined interfaces, allowing a class to use any number of interfaces within program execution, by explicitly declaring them when the pertinent class is defined.
In this tutorial, I’ll introduce the use of user-defined interfaces in PHP5, covering the basics of its theory along with the implementation of different examples, aimed specifically at demonstrating its functionality in real applications.
Before we get started, a few items with be required. You should have at least a basic familiarity with the PHP5 syntax, along with an intermediate knowledge of concepts related to object-oriented programming. Therefore, having defined the objectives of the article, let’s move on to learning about user-defined interfaces in PHP5.