我得叫test.php的具有功能和類的命名空間文件:不能在PHP
namespace Test;
function testFunc(){}
class TestClass{}
那麼如果在另一個文件I「用」這兩個命名空間的元素,類作品,但不是功能:
use Test\testFunc,
Test\TestClass;
include "test.php";
new TestClass();
testFunc();
的TestClass的對象被創建很好,但我得到testFunc()一個致命的錯誤:
Fatal error: Call to undefined function testFunc()
我認爲功能是由命名空間支持的。我究竟做錯了什麼?
編輯:說明這裏 - http://www.php.net/manual/en/language.namespaces.faq.php#language.namespaces.faq.nofuncconstantuse
所以基本上你不能導入功能一樣類?這個例子也沒有說明常量,我假設它們是相同的?其實,這裏有一個更清晰的解釋 - http://www.php.net/manual/en/language.namespaces.faq.php#language.namespaces.faq.nofuncconstantuse – Gnuffo1 2011-04-13 10:30:30