2
Quote:
irmtfan wrote:
Also i have a question about the usage of these functions.
i use them like this:
xoops_load('XoopsLocal');
.....
XoopsLocal::number_format($VAL)
is the above code the only and most efficient way?
Also we need to add some more php functions to XoopsLocal class.
one of the important one is "strtotime" which is used to convert gregorian date string to the number.
we need to have it in Local to enhance it and use other kinds of "input dates strings" like hegira date strings.
so finally all developers should use it like this: XoopsLocal::strtotime($datestring)
The code works but there is another way.
The class was made to support magic calls. The idea is that you don't have to add strtotime in XoopsLocalAbstract to be able to use a php function.
The catch is that this magic only happens if you instantiate the class like this:
XoopsLoad::load('XoopsLocal');
$local = new XoopsLocal;
echo $local->intval(5);
It will output '5' although the intval method is not present in the class.
If you use $local->strtotime($datestring) and you have this method on your localized class it would work just fine.
Personally, I dislike magic calls as they obfuscate the logic/code. I would prefer adding new methods in the abstract class as you suggested.
If you could do me a list of all php functions that require localization please post them here, I'll add them in 2.6.
For easier access, we could use $xoops->local->strtotime($datestring) and avoid some paper work.