You can use closures (>=PHP5.3) to store functions in variables.
For example:
class Test {
public $test1_1;
public function test1() {
$this->test1_1 = function() {
echo 'Hello World';
};
}
public function __call($method, $args) {
$closure = $this->$method;
call_user_func_array($closure, $args);
}
}
$test = new test();
$test->test1();
$test->test1_1();
Or you could create another object with the function you want and store that in Test.
class Test {
public $test1;
public function __construct(Test1 $test1) {
$this->test1 = $test1;
}
}
class Test1 {
public function test1_1 {
echo 'Hello World';
}
}
$test1 = new Test1();
$test = new Test($test1);
$test->test1->test1_1();
I don't see what you would accomplish by writing a function within another function. You might as well write two functions.