如何强制PHP / Apache来使用一年? [英] How to force PHP/Apache to use another year?

查看:135
本文介绍了如何强制PHP / Apache来使用一年?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我被交给另一名雇员的老项目。这是可怕的codeD,几乎让我放弃我的工作。两次。因为我没有那么多的时间(我得到了2周的这个任务),我不能重写整个事情。我修改它,因为我被要求,目前,我正在做的testings。问题是,在code应该改变它在其他年份的行为。这个问题的问题是,还有就是当年没有设置中央位置,它使用日期(Y)一切都在code这将逼我改变周围的200个文件。

So, I was handed an old project by another employee. It's horribly coded and almost made me quit my job. Twice. Because I don't have that much time (I was given 2 weeks for this task), I can't rewrite the entire thing. I modified it as I was asked, and currently, I'm doing the testings. The problem is, the code should alter it's behavior in other years. The problem with this problem is, that there is no central location where the current year is set, it's all over the code using date("Y") which would force me to change around 200 files.

所以,最简单的解决办法是告诉PHP在开头:嘿,这是一年20XX。我试图 date_default_timezone_set(),但这并没有帮助我在所有。所以,我正在寻找的是:

So, the easiest solution would be to tell PHP in the beginning: "Hey, it's year 20xx". I tried date_default_timezone_set(), but this didn't help me at all. So what I'm looking for is:


  • 一个PHP命令从而改变了当年设定值(如 Set_Date(Y,2016年);

  • 一个Apache Servercommand从而改变当前的时间(如的setdate -Y 2016年

  • A PHP-command which changes the current year to the set value (likeSet_Date("Y", 2016);)
  • An Apache-Servercommand which changes the current time (likesetdate -Y 2016)

有什么办法或至少是一个解决方法,以使脚本认为这是又一年?

Is there any way or at least a workaround to make the script think it's another year?

推荐答案

您可以通过重新定义函数的 runkit_function_redefine()

但是,你需要设置 runkit PECL扩展

You can redefine functions using runkit_function_redefine()
But you need to setup the runkit PECL extension

注意:我没有测试它

<?php 
print date("Y");

$date = 'print "Hello, it is a new definition of date function <" . $Y . ">"; return 2014; ';
runkit_function_redefine('date', '$Y', $date);

date("Y");

这篇关于如何强制PHP / Apache来使用一年?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆