有没有一种方法可以将 PHP 作为比安装版本更旧的版本来执行?
我需要在服务器上支持一些遗留代码,我需要始终使用最新的稳定 PHP 版本。我不可能每次升级时都更新代码库,所以我想知道是否有一种方法可以使用比已安装版本更旧的 PHP 版本运行此特定站点。
示例:我正在运行 PHP 5.3.3,但旧站点的代码已损坏。它在 5.2.x 上完美运行。我是否可以简单地在脚本顶部放置一个命令以将其作为 5.2.x 运行,这样下次升级到 5.4、5.5 等时就不必修复损坏的代码?
TL;DR:是否有这样的函数:
exec_as_php_version('5.2.14');//?
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');//?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,没有。欢迎来到版本依赖地狱。
编辑:10 年后的现在,这不会太困难 - 只需在单独的 Docker 容器中运行不同的 PHP 版本即可。不过,出于安全原因,运行非常旧的 PHP 版本仍然是一个坏主意。
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.
它永远不向前兼容。
这是我之前见过的一个解决方案,但这是一个非常糟糕的主意: http://blog.dynom.nl/archives/Multiple-PHP-versions-on-one-webserver_20091103_53.html(已存档2014-02-23)。
it is never forward compatible.
this is one solution i have seen earlier, but it is a VERY BAD IDEA: http://blog.dynom.nl/archives/Multiple-PHP-versions-on-one-webserver_20091103_53.html (archived 2014-02-23).