PHP Handbuch
Zurück | Anhang B. Migrating from PHP 4 to PHP 5 | Nach vorne

# Backward Incompatible Changes

Although most existing PHP 4 code should work without changes, you should pay attention to the following backward incompatible changes:

- strrpos() and strripos() now use the entire string as a needle.

- Illegal use of string offsets causes `E_ERROR` instead of `E_WARNING`.

- array_merge() was changed to accept only arrays. If a non-array variable is passed, a `E_WARNING` will be thrown for every such parameter. Be careful because your code may start emitting `E_WARNING` out of the blue.

- PATH_TRANSLATED server variable is no longer set implicitly under Apache2 SAPI in contrast to the situation in PHP 4, where it is set to the same value as the SCRIPT_FILENAME server variable when it is not populated by Apache. This change was made to comply with the CGI specification. Please refer to bug #23610 for further information.

- The `T_ML_CONSTANT` constant is no longer defined by the Tokenizer extension. If error_reporting is set to `E_ALL`, PHP will generate a notice. Although the `T_ML_CONSTANT` was never used at all, it was defined in PHP 4. In both PHP 4 and PHP 5 // and /* */ are resolved as the `T_COMMENT` constant. However the PHPDoc style comments /** */ ,which starting PHP 5 are parsed by PHP, are recognized as `T_DOC_COMMENT`.

- $_SERVER should be populated with argc and argv if variables_order includes "S". If you have specifically configured your system to not create $_SERVER, then of course it shouldn't be there. The change was to always make argc and argv available in the CLI version regardless of the variables_order setting. As in, the CLI version will now always populate the global $argc and $argv variables.

- An object with no properties is no longer considered "empty".

- Classes must be declared before used.

Beispiel B-1. strrpos() and strripos() now use the entire string as a needle
`<?php var_dump(strrpos('ABCDEF','DEF')); //int(3) var_dump(strrpos('ABCDEF','DAF')); //bool(false) ?>`

Beispiel B-2. An object with no properties is no longer considered "empty"
`<?php class test { } $t = new test(); var_dump(empty($t)); // echo bool(false) if (!$t) { // Will be executed } ?>`

The following example was valid in PHP 4, although it will produce a fatal error in PHP 5.

Beispiel B-3. Classes must be declared before used
`<?php $test = new fubar(); $test->barfu(); class fubar { function barfu() { echo 'fubar'; } } ?>`

Zurück | Zum Anfang | Nach vorne
Migrating from PHP 4 to PHP 5 | Nach oben | CLI and CGI