将没有命名空间的类导入命名空间类
我有一个类,它包括 Smarty,但我的类使用命名空间测试,Smarty 不使用命名空间.如何包含 Smarty,而不将命名空间写入 smarty 文件(它有许多系统插件)
I have a some class, it include Smarty, but my class use namespace test, Smarty don't use namespaces. How include Smarty, without writing namespaces into smarty files (it has many system plugins)
import "smarty/Smarty.php"
class testik
{
public function __construct ()
{
$smarty = new Smarty();
}
}
<?php
class Smarty
{
//somcode
}
Smarty 有自动加载器类并包含它的插件,插件也没有命名空间.
Smarty has autoloader class and include its plugins, plugins haven't namespaces too.
推荐答案
告诉你的命名空间代码它在全局命名空间中:
Tell your namespaced code it's in the global namespace:
$smarty = new Smarty();
另外导入Docs 以这种方式工作:
Additionally importingDocs works this way:
use Smarty;
然后您可以按原样使用您的代码:
Then you can use your code as it was:
$smarty = new Smarty();
另见:如何使用php的root"命名空间?.
相关文章