Advanced usage

Advanced usage – Describe techniques for advanced usage

Advanced usage

In order to create portable code, it's best to assume all the native functions already exist. Littering a script with calls to PHP_Compat can become messy, and increase the work required to port the code.

To solve this there are a number of approaches. The first would be adding the load statements to a file which is included at the top of every document. The second, and preferred method is to make use of php_auto_append php.ini value. This can be set in a .htaccess file, and no modifications to the actual code are required.

If phpcompat.php was the name of the file, an example entry in a .htaccess could be php_value php_auto_append phpcompat.php. The phpcompat.php file would make use of either the loadVersion or loadFunction/loadConstant methods discussed in the next page.