Using a singleton class to get and set program wide settings The following code works and does what I want, but I'd like to confirm I'm using this OOP concept correctly. I'm using the following class to get and set some configuration parameters for my program. It used $GLOBALS for this before, but I'm trying to use a singleton pattern for this instead.

Below is the Config class. Does anything jump out as aggressively stupid? Seeing as how I'm going to be including this in most files any way I figured it would make sense to throw the autoload function in there too- is this bad design?

&lt;?php

  //This class will be included for every file
  //needing access to global settings and or
  //the class library

  spl_autoload_register(function($class){
      require_once 'classes/' . $class . '.php';
  });

  final class Config {

      private static $inst = null;

      //Array to hold global settings
      private static $config = array(
          'mysql' =&gt; array(
              'host' =&gt; '127.0.0.1',
              'username' =&gt; 'root',
              'password' =&gt; '123456',
              'db' =&gt; NULL
          ),
          'shell' =&gt; array(
              'exe' =&gt; 'powershell.exe',
              'args' =&gt; array(
                  '-NonInteractive',
                  '-NoProfile',
                  '-NoLogo',
                  '-Command'
              )
          )
      );

      public static function getInstance() {
              if (static::$inst === null) {
                  static::$inst = new Config();
              }
              return static::$inst;
      }

      public function get($path=NULL) {

          if($path) {
              //parse path to return config
              $path = explode('/', $path);

              foreach($path as $element) {
                  if(isset(static::$config[$element])) {
                      static::$config = static::$config[$element];
                  } else {
                      //If specified path not exist
                      static::$config = false;
                  }
              }
          }

          //return all configs if path NULL
          return static::$config;
      }

      public function set($path=NULL,$value=NULL) {

          if($path) {
              //parse path to return config
              $path = explode('/', $path);
              //Modify global settings
              $setting =&amp; static::$config;

              foreach($path as $element) {
                      $setting =&amp; $setting[$element];
              }

              $setting = $value;
          }
      }

          //Override to prevent duplicate instance
          private function __construct() {}
          private function __clone() {}
          private function __wakeup() {}
  }


I access it like so:

$aaa = Config::getInstance();
var_dump($aaa-&gt;get());
$aaa-&gt;set('mysql/host','zzzzzzzzzzzz');
var_dump($aaa-&gt;get());


I read a little bit about how singletons are less useful in php. I will research that further at some point, but for the time being I just want to make sure I'm doing this right.
There should be something about a Singleton class that requires that it allow and present a single, globally available, instance.  Otherwise, the pattern is being misused.

The way your class is built, there's not really such a reason.  You could have any number of instances, and they'd all work (though they'd all look like the same instance anyway).

As for recommendations to make things less weird...?


Use instance variables.

Everything is essentially global.  (Make no mistake; hiding it in a class doesn't do much at all to change that.  static is just how a lot of OO languages spell "global".  :P)  Your "instance" is just an interface to get and set that global stuff.  Every "instance" has the same ability, since it gets and sets the same variables -- and in fact, any update through one "instance" will be reflected in every other.  So new Config and Config::getInstance() really differ only in whether another instance is created.  The caller could say one or the other, and get the exact same results.

If you insist on a singleton, moving the static variables into the instance would legitimize the existence of an instance at all, and provide a less dodgy reason to require exactly one authoritative instance.  (Though it'd also prompt the question, "Why can't i create a separate configuration for testing?".  Among others.)
Lose the public setter, or provide a way to disable it.

There's next to no encapsulation or data hiding going on here; the only thing that even remotely counts is your path stuff.  Any caller can change global settings at will.  This kind of "action at a distance" can cause all kinds of weirdness.  It is the very reason mutable global state is discouraged, and set makes it even easier to abuse.

You should consider either getting rid of the setter, making it private (and thus disabling outside modification altogteher), or adding some way for your setup code to disable it -- effectively "freezing" the instance -- once the configuration is established.
Use self::, not static::.

static (when used in place of a class name) uses PHP's "late static binding" to look up variables through the name of the called class rather than the one where the method lives.  It's there to allow subclasses to override static members.  But you've explicitly disallowed inheritance...so values will only ever be looked up in this class.  static is thus wasteful, and a bit of a mixed message.
As for the autoloader, it's not exactly a mortal sin or anything to put that in the same file as the config class.  Unless the classes are going to be moving around, though, their current location isn't really part of the config settings, is it?

I'd suggest making the autoloader a part of the startup code, unless the class files are going to move around (thus making the current location a part of the configuration).