Skip to content

Instantly share code, notes, and snippets.

@uppfinnarjohnny
Created February 6, 2012 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uppfinnarjohnny/1752699 to your computer and use it in GitHub Desktop.
Save uppfinnarjohnny/1752699 to your computer and use it in GitHub Desktop.
<?php
function val_somewhat_nested($name = null, $value = null, $is_mutable = false) {
static $values = array();
static $mutables = array();
if($name === null)
return $values;
if($value === null)
return isset($values[$name]) ? $values[$name] : null;
if(isset($values[$name]) && ! in_array($name, $mutables))
throw new Exception('The value "' . $name . '" is immutable and has already been set to '.$values[$name].'.');
if($is_mutable)
$mutables[] = $name;
return $values[$name] = $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment