Reputation: 2444
I've gotten this really strange error all of a sudden in a legacy application we maintain.
Uncaught Error: Call to undefined method DateTime::format() in PATH/helpers.php:54
My relevant code is this:
function custom_date_format($str, $format=false){
if(!$format){
$format ="j M Y";
}
$date = DateTime::createFromFormat('d-m-Y', $str);
if($date){
return $date->format($format); // lineno 54
}
return '';
}
The server is running PHP 7 and DateTime::createFromFormat
appears to be working so the DateTime
object is working as it should.
It stopped working overnight (which I find really strange, and not sure if I believe it).
Any idea's of such strange errors?
Upvotes: 2
Views: 2096
Reputation: 2444
We figured it out and the answer is not at all satisfying:
The bug was not repeatable in a reliable way. It was there intermittent. That is already cause for suspicion.
After some digging there were more processes reporting erratic behavior and it appears that a memory problem is the root cause. After migrating to a 'fresh' server all the problems are gone.
So apparently the DateTime object was not fully allocated in a way? The format function pointer was overwritten or something. But the faulty memory was causing it.
Upvotes: 2