Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Created November 3, 2014 19:59
Show Gist options
  • Save xeoncross/6ec5754ba74619218df7 to your computer and use it in GitHub Desktop.
Save xeoncross/6ec5754ba74619218df7 to your computer and use it in GitHub Desktop.
A simple singleton registry store inside an function that provides public read/write access to it's datastore
<?php
function o($key = null, $value = null) {
static $registry;
if( ! $key) {
return $registry;
}
if(is_array($key)) {
return $registry = $key;
}
if($value) {
return $registry[$key] = $value;
}
if(isset($registry[$key])) {
return $registry[$key];
}
}
@jm42
Copy link

jm42 commented Nov 19, 2014

I added this to the list of 140 bytes because of:

function o($k=null,$v=null){static $r;if(!$k) return $r;if(is_array($k))return $r=$k;if($v)return $r[$k]=$v;if(isset($r[$k]))return $r[$k];}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment