[UPHPU] $GLOBALS and global best practices

Sean Thayne sean at skyseek.com
Mon Nov 7 18:23:49 MST 2011


class Settings 
{
    protected $_instance;

    public static function getInstance() 
    {
        if(!self::$_instance)
              self::$_instance = new Settings()

        return self::$_instance;
    }
}


Random portion of code...

$settings = Settings::getInstance();


Sorry, did this on my phone. But this is the way to do singletons in PHP ;)


- Sean Thayne

On Nov 7, 2011, at 3:12 PM, Steve Meyers <steve-uphpu at spamwiz.com> wrote:

> On 11/7/11 3:05 PM, Daniel C. wrote:
>> Not necessarily.  The old import() function appears to be gone (thank
>> goodness) but we still have import_request_variables() and extract()
>> which appear somewhat better than import() but could still potentially
>> land you in the same boat:
>> 
>> http://us.php.net/manual/en/function.import-request-variables.php
>> http://us.php.net/manual/en/function.extract.php
> 
> Yes, but we're still operating under the assumption that security 
> doesn't matter, since you're importing arbitrary variables into your 
> namespace.
> 
> Steve
> 
> _______________________________________________
> 
> UPHPU mailing list
> UPHPU at uphpu.org
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net


More information about the UPHPU mailing list