[Phpmyadmin-devel] PMA_CommonFunctions

Chanaka Dharmarathna pe.chanaka.ck at gmail.com
Sat Sep 15 09:02:12 CEST 2012


>> I stumbled upon this piece of code (random pick) :
> >>
> >> PMA_CommonFunctions::getInstance()->backquote($_REQUEST['view']['name'])
> >>
> >> and it made me wonder if using a singleton for PMA_CommonFunctions is
> >> necessary, because basicaly PMA_Commonfunctions is a collection of
> >> methods, not really a 'living' object.
> >> So then I had a look at the class, and I discovered that the class has
> >> no class variables (apart from the _instance variable) and an empty
> >> constructor.

Exactly, that class has no properties except _instance which needed for
implement this pattern for refer to the class instance itself. So this is
not a living object.

I search bit more in this kind of cases and get to know that, this kind of
utility classes are making static. And it is faster than singleton class.
>From the both approaches our work can be done. But not the exact need for
use singleton pattern here.

> >> So basicly this should be a static class, with static methods, because
> >> no instance is needed for it to work.
> >>
> >> And the above piece of code will become :
> >>
> >> PMA_CommonFunctions::backquote($_REQUEST['view']['name'])
> >>
> >> BTW: If you convert it to a static class, don't forget to replace the
> >> $this->method() calls by the static equivalent self::method().

I'll do the necessary modifications if others think this approach is good.

Regards !
Chanaka Dharmarathna
*Virtusa (Pvt) Ltd. | **Sri Lanka*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.phpmyadmin.net/pipermail/developers/attachments/20120915/84a0ea88/attachment.html>

More information about the Developers mailing list