phpversion

Is there a way to execute PHP as an older version than the one installed?


I need to support some legacy code on a server where I need to be on the latest stable PHP version at all times. I can't possibly update the code base every time I upgrade so I'm wondering if there is a way to run this specific site with an older version of PHP than the one installed.

Example: I'm running PHP 5.3.3 and my code for an old site is broken. It was running perfectly on 5.2.x. Can I simply put a command in at the top of the script(s) to run it as 5.2.x so that I don't have to fix broken code the next time I upgrade to 5.4, 5.5, etc?

TL;DR: Is there a function like this:

exec_as_php_version('5.2.14');//?


Solution

  • No, there isn't. Welcome to version dependence hell.

    Edit: Now, 10 years later, this would not be terribly difficult - just run different PHP versions in separate Docker containers. It's still a bad idea to run really old PHP versions for security reasons, though.