将没有命名空间的类导入命名空间类 [英] Importing class without namespace to namespaced class

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

问题描述

我有一个类,它包括 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的root"命名空间?.

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

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