Skip to content

Instantly share code, notes, and snippets.

@riaf
Created November 16, 2010 06:36
Show Gist options
  • Save riaf/701530 to your computer and use it in GitHub Desktop.
Save riaf/701530 to your computer and use it in GitHub Desktop.
読めるけど書けない
<?php
/**
* Niigata Class
*
* @author Keisuke SATO aka riaf <[email protected]>
* @license New BSD License
**/
class Niigata
{
protected $_niigata_ = array();
public function __get($name) {
if (isset($this->_niigata_[$name])) {
return $this->_niigata_[$name];
}
$class = get_class($this);
trigger_error("Undefined property: $class::\$$name", E_USER_NOTICE);
}
public function __isset($name) {
return isset($this->_niigata_[$name]);
}
public function __set($name, $value) {
$d = debug_backtrace();
if (isset($d[1]) && isset($d[1]['class']) && is_subclass_of($d[1]['class'], __CLASS__)) {
$this->_niigata_[$name] = $value;
} else {
$class = get_class($this);
trigger_error("Cannot access niigata property $class::\$$name", E_USER_WARNING);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment