Re: I18N_DateTime unsing static instance

From: Date: Wed, 21 May 2003 13:59:56 +0000
Subject: Re: I18N_DateTime unsing static instance
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-16577@lists.php.net to get a copy of this message
Zitat von Wolfram Kriesing <wolfram@visionp.de>: > Jan Schneider wrote: > > 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. > > yeah sounds cool too. > so you would always have to carry the LOCALE-varibale/constant around > in the code? (it's now represented by 'de_DE') > or should it work like this: > > very first call: > $dateTime = &I18N_DateTime::singleton('de_DE'); > > every other call would/could be: > $dateTime = &I18N_DateTime::singleton(); > in the second call you wouldnt need the LOCALE, since the singleton > was 'initialized' before That doesn't quite follow the singletno pattern, but actually it depends how you code the singleton() method. I'd advise you to use the locale everytime though, because the whole purpose of the singleton is that you always get an object instance back without having to care about the actual instantiation. > or better like this: > &I18N_DateTime::setup('de_DE'); > > //and somewhere in the code: > $dateTime = &I18N_DateTime::singleton(); > Lukas, what's your opinion. since you started all this hustle :-) Jan. -- http://www.horde.org - The Horde Project http://www.ammma.de - discover your knowledge http://www.tip4all.de - Deine private Tippgemeinschaft

« previous php.pear.dev (#16577) next »