Re: I18N_DateTime unsing static instance
| From: | Wolfram Kriesing | Date: | Wed, 21 May 2003 13:38:25 +0000 |
| Subject: | Re: I18N_DateTime unsing static instance | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-16576@lists.php.net to get a copy of this message | ||
Jan Schneider wrote:
Zitat von Wolfram Kriesing <wolfram@visionp.de>: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: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() {Why don't you just add a singleton method to the class, so you can do something like: 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 thisI18N_DateTime::formatShort($timestamp,'de_DE'); // 'de_DE' could also be a constantthis 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$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.
$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' beforeor 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 :-)
--
Wolfram
... opensource @ vision:produktion ...
http://opensource.visionp.de
... translating template engine ....
http://sf.net/projects/simpletpl
... authentication system ....
http://sf.net/projects/auth