php中的名称空间函数
我在名称空间和函数方面遇到问题。我使用的是PHP7 我有一个文件:php中的名称空间函数,php,function,namespaces,Php,Function,Namespaces,我在名称空间和函数方面遇到问题。我使用的是PHP7 我有一个文件: namespace profordable\app; function get_app() { if (!class_exists('profordable\app\app')) { return false; } global $global; if (!isset($$global)) { return false; } return $$gl
namespace profordable\app;
function get_app() {
if (!class_exists('profordable\app\app')) {
return false;
}
global $global;
if (!isset($$global)) {
return false;
}
return $$global;
}
class app {
...
}
和我的主索引文件:
namespace profordable\app;
$global = 'app';
$app = new app;
和另一个文件作为文件(全局命名空间):
我似乎无法获取文件中的get_app函数,我已经测试过了,并且
var_dump(function_exists('profordable\app\get_app');
返回true,但当我尝试(在文件中)的组合时
它不起作用。请帮助这在文件中起到了作用:
use function profordable\app\get_app as get_app;
它做什么或不做什么?错误是什么?没有错误,get_app()只返回null
use profordable\app;
use function profordable\app\get_app;
function some_function() {
$app = get_app();
$app = profordable\app\get_app();
$app = \get_app();
...etc
}
use function profordable\app\get_app as get_app;