Skip to content

Instantly share code, notes, and snippets.

@grakic
Created April 6, 2011 00:32
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 grakic/904897 to your computer and use it in GitHub Desktop.
Save grakic/904897 to your computer and use it in GitHub Desktop.
<?php
abstract class stdConst
{
private $c;
public function __construct($c)
{
// requirement is for a class to be named <Something>Const
// so static methods can be called on <Something>
if(substr(get_called_class(), -5) != 'Const') {
throw new RuntimeException('stdConst class name must end with Const keyword');
}
$this->c = $c;
}
public function __set($n, $v)
{
throw new RuntimeException(get_called_class() . ' can not be modified');
}
public function __get($n)
{
return $this->c->$n;
}
public function __isset($n)
{
return isset($this->c->$n);
}
public function __unset($n)
{
throw new RuntimeException(get_called_class() . ' can not be modified');
}
public function __call($n, $a)
{
return call_user_func_array(array($this->c, $n), $a);
}
public static function __callStatic($n, $a)
{
// get non-constant class name, and call a static method
$class_name = substr(get_called_class(), 0, -5);
return call_user_func_array(array($class_name, $n), $a);
}
public function __toString()
{
return $this->c->__toString();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment