Last active
February 12, 2018 05:46
-
-
Save firasd/5cbbe6c73640cb18f75a1e04674edecf to your computer and use it in GitHub Desktop.
PHP Singleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class scriptmem { | |
public static $cache; | |
public static function init() { | |
if(self::$cache === null) { | |
self::$cache = array(); | |
} | |
return self::$cache; | |
} | |
public static function get($ckey) { | |
$res = false; | |
$cache = self::init(); | |
if(array_key_exists($ckey, $cache)) { | |
$res = $cache[$ckey]; | |
} | |
return $res; | |
} | |
public static function set($ckey, $cval) { | |
$cache = self::init(); | |
self::$cache[$ckey] = $cval; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment