[Phpmyadmin-devel] about $common_functions

Rouslan Placella rouslan at placella.com
Tue Jul 3 16:00:15 CEST 2012


On 03/07/12 14:51, Marc Delisle wrote:
> Le 2012-07-03 09:38, Rouslan Placella a écrit :
>> On 03/07/12 14:34, Marc Delisle wrote:
>>> Hi,
>>> I just made a suggestion to Thilina but I want to validate it with
>>> everyone.
>>>
>>> I see a lot of
>>> $common_functions = PMA_CommonFunctions::getInstance()
>>>
>>> inside many functions of the same library. If we know that this library
>>> is always called from one script, I believe it would be more efficient
>>> to do this instead, inside the functions:
>>>
>>> global $common_functions;
>>>
>>> and ensure that $common_functions has been defined in the global scope
>>> of the calling script.
>>>
>>
>> Doesn't that defeat the purpose of having a singleton class?
>
> Well, I don't understand the definition of a singleton. From [0],
> "the singleton pattern is a design pattern that restricts the
> instantiation of a class to one object"
>
> Does that mean that one such object must exist inside a function, or
> must exist considering all scopes?

There will be only one in all scopes. However I thought that we were 
trying to reduce the number of globals that we have, since sometimes we 
get problems with undefined globals. Also, if we have a global reference 
to the commonFunctions object, then I see no point in restricting the 
number of instances.




More information about the Developers mailing list