Expose “use” classes to Included file

2019-01-20 15:31发布

Example:

namespace Somenamespace;    
use Somenamespace\Someclass;
use Somenamespace\otherclass;


class Template{

  public function display($templ){
    load_template($templ);
  }

}


function load_template($file){
  unset($file);
  require func_get_arg(0);
}

$template = new Template();
$template->display('file.php');

Now I want to access "Someclass" in file.php, without having to declare it first in the "use" statement. eg. someclass::dostuff(); (without the namespace)

Is it possible?

1条回答
老娘就宠你
2楼-- · 2019-01-20 16:28

Simply: no. See note bellow the example http://www.php.net/manual/en/language.namespaces.importing.php#example-247

Importing rules are per file basis, meaning included files will NOT inherit the parent file's importing rules.

查看更多
登录 后发表回答