PHP how can I return the calling function (to avoid the scope of the function)


I have two files:


<div><?php echo $myVar; ?></div>


class MyClass extends Base {
    public function view() {
        $myVar = 'hello world';
abstract class Base {
    public function loadTemplate($template) {

but this must not works because the require is in scope of loadTemplate function, how can i return the call to require function in the loadTemplate? i want the require be included in the view() scope using single function like $this->loadTemplate(); and not using require_once($this->getTemplatePath())

any idea?

You can't. Generally what you're trying to do is accomplished by passing an array with your variables ($this->loadTemplate(array('myVar' => 'hello world'))) and then calling extract($vars) in the loadTemplate method.