PHP: How to access functions outside of namespace class that are in another class with no namespace?

时间:2017-04-24 17:29:49

标签: php namespaces

My main script has a namespace of "App". I have imported another PHP script into my main script.

My main script thinks the function is part of App... when it's not. It's in the other PHP script.

How do I access functions that are outside of the namespace?

1 个答案:

答案 0 :(得分:0)

第一个选项是在该特定的php文件上导入命名空间然后你可以别名;意思是你告诉php你将使用较短的名称引用导入的类,接口,函数或常量。从PHP 5.6开始,可以导入函数和常量。这需要调整才能使用关键字语法。要导入功能:

<?php 

 use func Namespace\functionName;

 functionName();

?>