I’m looking for a way to extend a PHP class to add a custom method. In particular I want to add a date-format method to MongoDate (from the PHP MongoDB driver).
I just thought it would be much cleaner, if the MongoDate object received from a Mongo collectio, provides a method to make it readable, and not having the need to call a function or class to do that.
$d = new MongoDate();
some_date_format($d); // the way it works now
$d->format(); // the way it would be cleaner
Is there any solution?
Inherit from it!
Then just implement it: