Skip to content

Instantly share code, notes, and snippets.

@firasd
Last active February 12, 2018 05:46
Show Gist options
  • Save firasd/5cbbe6c73640cb18f75a1e04674edecf to your computer and use it in GitHub Desktop.
Save firasd/5cbbe6c73640cb18f75a1e04674edecf to your computer and use it in GitHub Desktop.
PHP Singleton
<?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