暴露“使用”包含到包含文件的类 [英] Expose "use" classes to Included file

查看:115
本文介绍了暴露“使用”包含到包含文件的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例:

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');

现在我想访问file.php中的Someclass,而不必先在使用声明。例如。 someclass :: dostuff(); (没有命名空间)

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)

有可能吗?

推荐答案

简单地说:没有。请参阅示例 http://www.php。 net / manual / en / language.namespaces.importing.php #example-247

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


导入规则基于每个文件,意思是包含文件将 NOT 继承父文件的导入规则。

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

这篇关于暴露“使用”包含到包含文件的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆