Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP and singletons again

Tags:

php

singleton

class ConfigReader { private static $instance = NULL; protected $configData = array();

    public function getInstance()
    {
        if( self::$instance == NULL )
        {
            self::$instance == new ConfigReader();
        }
        return self::$instance;
    }

    public function getConfigValue( $getName )
    {
        echo 'In function';
    }

    private function __construct()
    {
        $this->configData = %READ_FROM_DATABASE%;
    }

    private function __clone() {}
}

And for:

var_dump( ConfigReader::getInstance() )

I got: NULL

I broke by brains... Help me, please.

like image 595
Max Frai Avatar asked Aug 28 '26 02:08

Max Frai


1 Answers

Just a typo: self::$instance == new ConfigReader() contains == instead of =

like image 180
Xeor Avatar answered Aug 30 '26 15:08

Xeor