Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class GetterSetter{
- protected $variables = array();
- public function __get($name){
- if (isset($this->variables[$name]){
- return $this->variable[$name]['value'];
- }
- throw new Exception($name . " not a member");
- }
- public function __set($name,$value){
- if (isset($this->variable[$name]){
- if (isset($this->variables[$name]['protected'] && $this->variables[$name]['protected']) throw new Excpetion('not allowed to edit');
- $this->variables[$name]['value']=$value;
- }
- throw new Exception($name . " not a member");
- }
- }
- class Example extends GetterSetter{
- protected $variables = array(
- 'foo' => array('protected'=>false,'value'=>'bar'),
- 'bar' => array('protected'=>true , 'value'=>'foo')
- );
- }
- $a = new Example;
- $a->foo='a';
- $a->bar ='b'; //throws an error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement