Importing class without namespace to namespaced class

假如想象 提交于 2019-11-27 21:35:55

问题


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 has autoloader class and include its plugins, plugins haven't namespaces too.


回答1:


Tell your namespaced code it's in the global namespace:

$smarty = new \Smarty();

Additionally importing­Docs works this way:

use Smarty;

Then you can use your code as it was:

$smarty = new Smarty();

See as well: How to use “root” namespace of php?.



来源:https://stackoverflow.com/questions/8574794/importing-class-without-namespace-to-namespaced-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!