A new engine for a mature language
PHP 5, released in July 2004, is the most significant revision of the language since its creation. At the heart of the change is the Zend Engine II, a rewrite of the execution engine that introduces an entirely new object model, aligned with the conventions of established OOP languages.
PHP 4 had rudimentary object support: objects were copied by value on every assignment, there were no visibility modifiers and inheritance was limited. PHP 5 addresses these shortcomings with an object architecture designed from scratch.
The object model
The new OOP model introduces the fundamental concepts of object-oriented programming in a comprehensive manner:
- Visibility: properties and methods can be declared
public,protectedorprivate, enabling encapsulation - Interfaces: contracts that define the methods a class must implement, without providing the implementation
- Abstract classes: classes that cannot be instantiated directly and serve as a base for inheritance
- Magic methods:
__construct(),__destruct(),__get(),__set()and other special methods that control the lifecycle and behaviour of objects - Exceptions: structured error handling with
try/catch/throw, replacing the procedural pattern of checking return codes
Objects in PHP 5 are passed by reference (more precisely, by handle): an assignment does not copy the object, but creates a new reference to the same object in memory. This aligns the behaviour with that of Java and C#.
PDO and data access
PDO (PHP Data Objects) is the new abstraction layer for database access. Unlike database-specific extensions (mysql_*, pg_*), PDO provides a unified interface that supports MySQL, PostgreSQL, SQLite, Oracle and other backends through interchangeable drivers.
PDO introduces prepared statements as a native mechanism, separating query structure from data and offering protection against SQL injection — a class of vulnerability widespread in PHP 4 applications that built queries by concatenating strings.
XML and interoperability
PHP 5 brings two new extensions for XML handling. SimpleXML allows XML documents to be navigated as PHP object structures with minimal syntax. DOM provides a complete implementation of the W3C Document Object Model for scenarios requiring structural document manipulation.
These extensions, combined with native SOAP support, position PHP 5 as a platform for developing web applications that need to interoperate with XML-based enterprise services.
With PHP 5, the language completes the transition from a scripting tool for dynamic pages to a platform for building structured web applications. The frameworks that will emerge in the coming years will build their architectures on the foundations laid by this release.
