[Phpmyadmin-devel] Clarification on Design of PMA_RecentFavoriteTable Class

Edward Cheng c4150221 at gmail.com
Thu Apr 17 06:17:45 CEST 2014


Hi,
I thought we have these code can avoid errors, in my new PR I improve it.
<pre>
/**
 * Returns class instance.
 *
 * @param string $type the table type
 *
 * @return PMA_RecentFavoriteTable
 */
public static function getInstance($type)
{
    if (is_null(self::$_instance)) {
        self::$_instance[$type] = new PMA_RecentFavoriteTable($type);
    } else {
        if (self::$_instance[$type]->table_type != $type) {
            self::$_instance[$type] = new PMA_RecentFavoriteTable($type);
        }
    }
    return self::$_instance[$type];
}
</pre>
Does my PR fix it?

2014-04-17 0:02 GMT+08:00 Chanaka Dharmarathna <pe.chanaka.ck at gmail.com>:
> Hi,
>
> It seems like, the latest PMA_RecentFavoriteTable is trying to behave as
> singleton design pattern. Is that a requirement ? I mean is there any reason
> for making it singleton ? By the way, there is good possibility to create
> new instances again and again with current logic.
>
> And the class has $table_type instance variable and more. Isn't it risky
> behaviour to share a static instance throughout the web server, which has
> instance variable which used in functions of that instance ?
>
> Regards !
> --
> Chanaka Dharmarathna
> http://chanakaindrajith.blogspot.com/
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/NeoTech
> _______________________________________________
> Phpmyadmin-devel mailing list
> Phpmyadmin-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/phpmyadmin-devel
>



-- 
Edward Cheng




More information about the Developers mailing list