PHP 的 y2k_compliance php.ini 设置做了什么?

What did PHP's y2k_compliance php.ini setting do?

这个问题纯粹是出于学术目的,因为该设置在 PHP 5.4 中被删除并且 2000 年已经过去很久了,但是有人知道 y2k-compliance 配置设置的作用吗?

PHP documentation 并没有告诉你太多:

y2k_compliance (boolean)

Enforce year 2000 compliance (will cause problems with non-compliant browsers)

所以,有用的信息不多!

从 Google 搜索中,我发现的唯一附加信息是 this page,它指出:

Some users may be using wildly outdated, noncompliant browsers. If for some bizarre reason you're sure that a number of your site's users fall into this group, then disable the y2k_compliance parameter; otherwise, it should be enabled.

y2k_compliance = On

Specifies whether or not the PHP script should be made year-2000 compliant. Making the PHP script Y2K compliant (by setting this directive to On) will cause problems with non-Y2K-compliant browsers.

更多信息,但仍然是非常高级的描述。

我一直无法找到有关此设置试图解决的问题或解决方法的任何技术信息。

那么,如果 y2k-compliance 标志被禁用,PHP 做了什么不同的事情?

不确定这是否有帮助,但我从 PHP3 中找到了一些旧文档,其中更详细地描述了 Y2K 合规性。正如预期的那样,它与处理 2 位数年份格式有关。

来源:archive.org:php.net/y2k.php3

Year 2000 Compliance and PHP

Like Perl, PHP is about as Year 2000 compliant as your pencil. It is the applications you write with PHP you need to worry about, not PHP itself.

There is an issue with the dates in cookies. Netscape originally specified that the expiry date on a cookie should be in a 2-digit year format. Due to all the y2k hype, they decided to change this behaviour in Netscape 4 and up. This doesn't mean that the 2-digit year is not y2k compliant. A 2-digit year of "13", for example will be understood as the year 2013 in Netscape. All browsers understand this 2-digit format, and thus this is the default in PHP. Some y2k fanatics still insist on never using a 2-digit year no matter what, and for those people PHP has a y2k_compliance configuration setting available in the php3.ini file.

好吧,这不是过去的爆炸吗!我至少有 10 年没见过这个了。

该行为很简单,实际上很容易追溯到 source code。它只会真正影响 PHP 引擎的一部分。

症结很简单。 RFC 850 (1983) 指定所有日期格式都应包含日期的最后 两个 数字。 RFC 822 改变了这一点。然而,这并不意味着所有浏览器都神奇地更新了甚至知道如何处理它。

出于这个原因,添加了这个标志,这样人们就可以根据他们有多少用户 运行 旧(当时)随意设置他们想要旧格式还是新格式浏览器。