How backwards compatible is php 5 with php 4?
-
20-08-2019 - |
Question
I work on a code base written in php 4. I'd like to go through the process of upgrading the code to php 5 (the latest version my host provides). I'm wondering if anyone else has gone through a similar upgrade experience and can share what gotchas/pitfalls there are, what has to change in my code, what is not backwards compatible between the two versions?
Solution
Take a look at the guide for migrating from PHP 4 to 5. Your existing PHP 4 code should mostly still work, though there are some backward-incompatible changes.
OTHER TIPS
Check out the Migrating from PHP 4 to PHP 5.0.x documentation page. The most important section is Backward Incompatible Changes. AS long as you didn't use classes and objects in your previous application, array_merge is probably the only major problem you can encounter.
DO NOT enable the zend.ze1_compatibility_mode
configuration variable.
In my experience, the main source of pain is when the code relies on features that were already deprecated in PHP 4. Those are typically:
- Register globals
- Magic quotes
- Old fashioned session management, aka session_register()
There's no search and replace that can help you to identify such stuff. Removing it leads to tons of hard-to-spot failures. Keeping them leads to unmaintainable code. Setting an aggressive error_reporting level leads to an endless flood of notices.