The new version of PHP has been considerably optimized thanks to the Zend Engine 2, as well as numerous new implemented functions.
The developers of the platform took into consideration the need for compatibility in the applications and the scripts created for the previous version, but some differences in the engine require certain modifications to the old code and certain adjustments in the new one. Directly from the support pages of php.net, we indicate the main points: all of the links open in new window.
Changes that are not compatible (complete source, php.net)
- There are some new reserved keywords.
- strrpos() and strripos() now use the entire string as the search topic.
- Illegal use of string offsets causes E_ERROR instead of E_WARNING. An example of illegal use is: $str = 'abc'; unset($str);.
- array_merge() was changed to accept only arrays. If a non-array variable is passed, an E_WARNING will be thrown for every such parameter. Be careful because your code may start emitting E_WARNING out of the blue.
- The PATH_TRANSLATED server variable was changed: see also the description of $_SERVER['PATH_TRANSLATED'] in the manual.
- An object with no properties is no longer considered "empty".
In some cases classes must be declared before use. It only happens if some of the new features of PHP 5 (such as interfaces) are used. Otherwise the behaviour is the old one.
- If there are functions defined in the included file, they can be used in the main file regardless of if they are before return() or after. If the file is included twice, PHP 5 issues fatal error because the functions were already declared. We recommend that you use include_once() instead of checking if the file was already included and conditionally return inside the included file.
-It is not possible to re-assign $this : the following example works on PHP4 (it gives "OK"), but under PHP5 produces a "fatal error":
- No comments allowed after shorthand echo block
-Constructors return a reference as default. The following example works under
PHP4 but under
PHP5 produces an E_NOTICE notice
. In this case the problem can be solved by removing &
PHP5 offers also new functions, for example:
If you use third party applications, cms, portals, forums, guestbook, etc, make sure that the application is compatible with PHP5 in the parent site of the application or script in question.
- array_combine() - Creates an array by using one array for keys and another for its values.
- array_diff_uassoc() - Computes the difference of arrays with additional index check which is performed by a user supplied callback function
- array_udiff() - Computes the difference of arrays by using a callback function for data comparison
- array_udiff_assoc() - Computes the difference of arrays with additional index check. The data is compared by using a callback function
- array_udiff_uassoc() -Computes the difference of arrays with additional index check. The data is compared by using a callback function. The index check is done by a callback function also
- array_walk_recursive()- Apply a user function recursively to every member of an array
- array_uintersect_assoc() - Computes the intersection of arrays with additional index check. The data is compared by using a callback function
- array_uintersect_uassoc()- Computes the intersection of arrays with additional index check. Both the data and the indexes are compared by using separate callback functions
- array_uintersect() - Computes the intersection of arrays. The data is compared by using a callback function