Re: I18N_DateTime unsing static instance
| From: | Jan Schneider | Date: | Wed, 21 May 2003 12:58:26 +0000 |
| Subject: | Re: I18N_DateTime unsing static instance | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-16570@lists.php.net to get a copy of this message | ||
Zitat von Wolfram Kriesing <wolfram@visionp.de>:
> i discussed the following issue with Lukas a while ago
> i would like some opinions on how to proceed best.
> currently the I18N_DateTime works like this:
> $dateTime =& new I18N_DateTime('de_DE');
> function some()
> {
> global $dateTime;
> //and somewhere else in the code you call
> $dateTime->formatShort($timestamp)
> // this returns smthg like this: 20.05.2003 12:10
> }
>
> * Static calling suggestion
> now Lukas asked me for allowing a static call to the method, so that
> you dont have to define the $dateTime-object as global inside a
> method/function. instead you would have to know the LOCALE ('de_DE')
> in this case, so that the code would look something like this
> I18N_DateTime::formatShort($timestamp,'de_DE');
> // 'de_DE' could also be a constant
> this is much shorter, no doubt, but that would mean i would make a
> seperate class like: I18N_Static_DateTime, because i would like to
> prevent the mess of having two ways inside the I18N_DateTime class.
> And it would need a slightly different logic. And since people would
> only use either one, there is no point in putting both ways in one class.
>
> * Future thoughts
> After starting some work on it i came to the conclusion, that the
> actual reason why this is needed is actually only because PHP4 doesnt
> have a short way, like the following:
> new I18N_DateTime('de_DE')->format($timestamp);
> but that will be available in PHP5. So i was thinking again, should
> the I18N_Static_DateTime really be implemented, if it might be tossed
> later anyway?
>
> * Why it's implemented as it is
> Just another thought of why i implemented it as shown in the first
> example. From my experience, you normally run a (web)application in
> one language at one time. So setting up one instance, which provides
> all the methods to convert date's and time's is fully sufficient. And
> provides less overhead, since there is one instance and it can be
> passed around. Otherwise you would be passing around the LOCALE-variable.
> It's this way in Java iirc and i think those people have been thinking
> about it enough.
>
> any thought appreciated, thank you
Why don't you just add a singleton method to the class, so you can do
something like:
function some()
{
$dateTime = &I18N_DateTime::singleton('de_DE');
$dateTime->formatShort($timestamp);
}
This way you make sure that there is only one instance and you don't need a
global object.
Jan.
--
http://www.horde.org - The Horde Project
http://www.ammma.de - discover your knowledge
http://www.tip4all.de - Deine private Tippgemeinschaft