有没有一种方法可以将 PHP 作为比安装版本更旧的版本来执行?

发布于 2024-09-28 20:07:53 字数 299 浏览 0 评论 0原文

我需要在服务器上支持一些遗留代码,我需要始终使用最新的稳定 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生来就爱笑 2024-10-05 20:07:53

不,没有。欢迎来到版本依赖地狱。

编辑: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.

不奢求什么 2024-10-05 20:07:53

它永远不向前兼容。

这是我之前见过的一个解决方案,但这是一个非常糟糕的主意: 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文