Let's say for example I had a localised date class where the normal usage was to create an object.
$d = new Date(mktime(), 'MM-DD-YYYY', array('locale' => 'es'));
Now, what if I didn't want to always create a new object explicitly, but instead wanted something more along the lines of...
<p>The date is <?php echo
Date::formatDate( mktime(), 'MM-DD-YYYY', array('locale'=>'es') );?>
</p>
In my formatDate
method, would it be a good idea to invoke the constructor to internally create a date object, or should I completely make all internal method calls static?
class Date {
function getLocalisedDate( $time, $format, $options ) {
$obj = Date::Date(
$time, $format, $options
); // invoke the constructor
return $obj->get();
}
};
I haven't developed many classes, I'm wondering if it's a common pattern in OO languages.