First of all I'm aware of this question: PHP Date bug. It was finally resolved on PHP 5.6.23. So as I'm moving some of my severs from PHP 5.6.17 to PHP 5.6.23 I want the proper behavior on all of servers. But the project is huge, so to change all the Date-class usages with version check is a bit overhead, as it must be a temporary approach.
So the questions are:
Could I somehow log unexpected behavior (some general decision, as there're a lot of usages as I said).
If it's not possible, you are free to suggest something else.
As I see it you basically have three options. All have their drawbacks and advantages.
// first backup the original method
uopz_backup (\DateTime::class, 'methodToOverwrite');
// delete the original method
uopz_delete(\DateTime::class, 'methodToOverwrite');
// override the method
uopz_function(\DateTime::class, 'methodToOverwrite', function($arg) {
// do customn stuff like check for versions and handling them differently here
if (version_compare(PHP_VERSION, '5.6.23', '<')) {
// fix stuff
return fixedstuff;
}
return default stuff;
});
// once you are done with your code restore the original method
uopz_restore (\DateTime::class, 'methodToOverwrite');
Pros:
Cons:
This would involve having version checks if statements all over your code.
Pros:
Cons:
It sounds like this thing that has the issue is something you are doing often. As such it would probably be better to abstract it away by putting it in a function / class.
Pros:
YourDate::getFirstTuesdayOfWeek()
Cons:
Imo the last option is the best because it keeps your code clean, easy to extent and easy to test. And on top of that it has the lowest level of wtfness.