[Phpmyadmin-devel] about $common_functions

Marc Delisle marc at infomarc.info
Tue Jul 3 16:05:32 CEST 2012


Le 2012-07-03 10:00, Rouslan Placella a écrit :
> 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.

Ok, so what do you think of this code snippet:

$query[] = $insert_command . 'INTO '
 . PMA_CommonFunctions::getInstance()->backquote($GLOBALS['db']) . '.'
 . PMA_CommonFunctions::getInstance()->backquote($GLOBALS['table'])
        . ' (' . implode(', ', $query_fields) . ') VALUES ('
        . implode('), (', $value_sets) . ')';

Does this follow the singleton principle?

-- 
Marc Delisle
http://infomarc.info






More information about the Developers mailing list