2016-12-24 116 views
0

我遇到了命名空間和函數的問題。我使用PHP 7php中的命名空間函數

我有一個文件:

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(); 
} 

我似乎無法獲取文件中的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 
} 

這是行不通的。請幫助

+0

這是什麼做還是不做?什麼是錯誤(s)? – Rasclatt

+0

沒有錯誤,get_app()只返回null – Nate

回答

0

,這並在文件中招:

use function profordable\app\get_app as get_app;