【发布时间】:2017-05-10 01:00:58
【问题描述】:
我在命名空间和函数方面遇到问题。我正在使用 php 7。
我有一个文件:
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;
另一个文件为 FILE(全局命名空间):
function some_function() {
$app = get_app();
}
我似乎无法在 FILE 中获取 get_app 函数,我已经对其进行了测试并且...
var_dump(function_exists('profordable\app\get_app');
返回 true,但是当我尝试(在 FILE 中)的组合时...
use profordable\app;
use function profordable\app\get_app;
function some_function() {
$app = get_app();
$app = profordable\app\get_app();
$app = \get_app();
...etc
}
它不起作用。请帮忙
【问题讨论】:
-
它做什么或不做什么?错误是什么?
-
没有错误,get_app() 只是返回null
标签: php function namespaces