PHP 4 support is a thing of the past. It is therefore becoming urgent to migrate to PHP 5 because in 2008 no new version of PHP 4 will be released (support will still be provided on security vulnerabilities until 08/08/2008).
The compatibility between PHP 5 and PHP 4 has been a major concern during the development of PHP 5, and a large majority of applications should be able to run on PHP 5 without problems, or require only minor modifications. There are however some differences and we will try to summarize them here to allow you a simple migration.
Why migrate?
New features
Better performance
Better security
Better stability
PHP 5 is strongly supported
What has changed with PHP 5?
the redesign of the PHP core which allows a complete support of object-oriented programming
XML support redesign
SQLite embedded database integration
integration of new extensions (JSON, Filter, ZIP, …)
the emergence of a common basis for managing database calls: PHP Data Object (PDO)
the use of object reflection ( introspection)
exceptions have appeared in PHP5
an E_STRICT error level has been added
appearance of the SPL (Standard PHP Library), a collection of useful internal classes
Although most existing PHP 4 scripts should work, it is worth noting some major differences that can lead to errors or different behaviors:
Object management (referencing)
the redesign of DOM support with the abandonment of the DomXML extension
MySQL extension is no longer included by default
new error mode E_STRICT
The new object model
The main novelty of PHP 5 is certainly the new object model. Object processing has been completely rewritten to achieve better performance and more functionality. To date the object model of PHP 5 is close to that of Java, it thus results from it a certain number of innovations: magic methods, visibility, (was already present in PHP4, the novelty it is the destroyer or more generally the magic methods), encapsulation, cloning, interfaces, abstract classes…
Objects are passed by reference
In PHP 4 the entire object was copied when it was assigned or passed as a parameter to a function. In PHP 5 objects are referenced by a pointer and not their value (one can think of a pointer as an object identifier).
Pass an object by reference
Objects are no longer passed by value but by reference. The result is that once transmitted to a function, a PHP 5 object will see its values evolve while in PHP 4 it is a copy that will be modified within the function, the original object will remain unchanged.
In PHP 4 to make an object pass as reference we could do it by prefixing the variable with the sign”&”. Test our Xxxx example by removing the”&” in the declaration of the “fctActionObject()” function, you will see that in one case the”$b” object is modified and in the other it is not (and because the modification was made on a temporary copy).