I came up with such a solution, now I can call the methods of the next-class class using - $this
class TEST { private $classes = array( 'pages'=>'Pages', 'users'=>'Users', ///..... other ); public static $objects = array(); public function __get($name) { if(isset(self::$objects[$name])) { return self::$objects[$name]; } if(!array_key_exists($name, $this->classes)) { return null; } $class = $this->classes[$name]; include('classes/'.$class.'.php'); self::$objects[$name] = new $class(); return self::$objects[$name]; } }
Now inside any class that is a descendant of TEST, I can call methods of any of its other heirs
require_once ('classes/TEST.php'); class View extends TEST { function foo () { $this->users->foo(); }
$this->user
- modelfak