[ create a new paste ] login | about

Link: http://codepad.org/Qnc938Wv    [ raw code | output | fork ]

PHP, pasted on Jan 13:
<?php

class a{

        public function __get($key) {
            if($key == 'obj') {
                if($this->_obj == null) { //PSEUDO this is what I intend to do :)
                   echo "creating ";
                   $obj = new StdClass();                        
                   $obj->what = get_class($this);
                   $this->_obj = $obj;
                }
                return $this->_obj;
            }
        }
    }

    class location extends a{
        protected $_obj = null;
        public function __get($key) {
            return parent::__get($key);
        }
    }

    class user extends a{
        protected $_obj = null;
        public function __get($key) {
            return parent::__get($key);
        }
    }

$l = new location();
echo $l->obj->what . "\n";

$u = new user();
echo $u->obj->what . "\n";

echo $l->obj->what . "\n";
echo $u->obj->what . "\n";

?>


Output:
1
2
3
4
creating location
creating user
location
user


Create a new paste based on this one


Comments: