Created
November 16, 2010 06:36
-
-
Save riaf/701530 to your computer and use it in GitHub Desktop.
読めるけど書けない
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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