function func2() { parent::func1(); parent::func2(); }
$drv->obj = $this; echo "before call {$method}\n"; print_r($this); call_user_func_array(array($drv, $method), $args); echo "after call {$method}\n"; // Uncomment this line to work without crash // $drv->obj = null; } function __destruct() { echo "A::__destruct()\n"; $this->close(); } } class myserv { private static $drv = null; static function drv() { if (is_null(self::$drv)) { self::$drv = new drv(); } return self::$drv; } } $obj1 = new A(1); $obj1->func1(); $obj2 = new A(2); unset($obj1); $obj2->func1();
<?php class A { private $var1 = 'var1 value'; protected $var2 = 'var2 value'; private function func1() { return "in func1"; } protected function func2() { return "in func2"; } public function __get($var) { return $this->{$var}; } public function __call($func, array $args = array()) { return call_user_func_array(array($this, $func), $args); } } $a = new A(); echo $a->var1, "\n"; echo $a->var2, "\n"; echo $a->func1(), "\n"; echo $a->func2(), "\n";