简体   繁体   English

是否可以在PHP的date()函数中重新定义一些预设格式?

[英]Is it possible to redefine some preset formats in PHP's date() function?

We've run into an unexpected issue using PHP's date("c") formatting in PHP 5.3. 我们在PHP 5.3中使用PHP的date(“ c”)格式遇到了意外的问题。

The format returns a value that is hostile to the datetime column type in MySQL 5.7 and above. 该格式返回的值与MySQL 5.7及更高版本中的datetime列类型不符。

We never realized we were vulnerable to this issue until we attempted to upgrade our MySQL install and we started getting errors from the DB. 在尝试升级MySQL安装并开始从数据库中获取错误之前,我们从未意识到我们容易受到此问题的影响。

Our use of date("c") is nearly ubiquitous in our PHP code, so we face a dilemma and my team is looking to me to solve. 在我们的PHP代码中,对date(“ c”)的使用几乎无处不在,因此我们面临一个难题,我的团队正在寻求我解决。

I want to redefine how PHP returns date("c") permanently for all scripts that run on my servers. 我想重新定义PHP如何为服务器上运行的所有脚本永久返回date(“ c”)。 Is there a way to branch the function to redefine this preset? 有没有一种分支功能可以重新定义此预设的方法?

Thanks in advance for your suggestions. 预先感谢您的建议。

As mentioned in the other comments, PHP 5.3 is extremely out of date and should no longer be used . 如其他注释中所述,PHP 5.3已过时,应不再使用 As of the time of writing this comment, support ended almost 5 years ago. 在撰写本文时,支持已在5年前结束。

I would suggest upgrading your PHP version as soon as possible to reduce the chances of security issues. 我建议尽快升级您的PHP版本,以减少出现安全问题的机会。

In regards to your issue, I think rather than re-defining the constant (which isn't possible without a custom PHP build) it would make more sense to do a regex find & replace across your codebase. 关于您的问题,我认为与其重新定义常量(没有自定义PHP构建是不可能的),不如在整个代码库中进行正则表达式查找和替换会更有意义。

There are only a few functions that accept date format string, so it shouldn't be too hard to replace them automatically. 只有少数函数接受日期格式字符串,因此自动替换它们应该不太困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM