将不带名称空间的类导入到带名称空间的类 [英] Importing class without namespace to namespaced class

查看:97
本文介绍了将不带名称空间的类导入到带名称空间的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,其中包括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 importing­Docs works this way:

use Smarty;

然后,您可以按原样使用您的代码:

Then you can use your code as it was:

$smarty = new Smarty();

另请参见:如何使用php的根"命名空间?.

这篇关于将不带名称空间的类导入到带名称空间的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆