Importing class without namespace to namespaced class(将没有命名空间的类导入命名空间类)
问题描述
我有一个类,它包括 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"命名空间?.
这篇关于将没有命名空间的类导入命名空间类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将没有命名空间的类导入命名空间类


- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Laravel 仓库 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01