Skip to content

Instantly share code, notes, and snippets.

@jaceju
Created January 11, 2013 06:04

Revisions

  1. jaceju created this gist Jan 11, 2013.
    15 changes: 15 additions & 0 deletions Singleton.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <?php

    trait Singleton
    {
    protected static $_instance = null;

    public static function getInstance()
    {
    if (static::$_instance === null
    || !(static::$_instance instanceof static)) {
    static::$_instance = new static();
    }
    return static::$_instance;
    }
    }