Search code examples
phpclassdesign-patternsregistry

PHP : Initialized vs static registry class in performance


is there a big difference between initializing registry class and using static methods in performance ?

for example

class Registry
{
 private static $data;

 public static function set($key,$value)
 {
   self::$data[$key] = $value;
 }

 public static function get($key)
 {
   return isset(self::$data[$key]) ? self::$data[$key] : false;
 }
}

on the other hand

class Registry
{
  private $data = array();

  public function set($key,$value)
  {
    $this->data[$key] = $value;
  }

  public function get($key)
  {
    return isset($this->data[$key]) ? $this->data[$key] : false;
  }

}

Solution

  • is there a big difference [...] in performance

    No. The main concern would be the imminent violations of Dependency Inversion with the first approach. The second approach would allow injection of the registry object, improving testability and extensibility.