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 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
