Namek Dev
a developer's log
NamekDev

Tag: php

Common code for Singletons using PHP's traits

February 22, 2015

I hate singletons. Some say that singletons are not bad, instead “singletonism” is the evil. I would argue. Anyway, I’ve been working on some common Singleton pattern code in PHP for a particular reason - I had to create common code for two basecodes:

  1. Laravel app using Facades
  2. some other custom API

Usage

class DataUtilsInst {
    use Singleton;

    public static function getClassName() {
        return '\NS\common\utils\DataUtils';
    }
}
→ Continue reading php