Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing class without namespace to namespaced class

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.

like image 216
TROODON Avatar asked Dec 20 '11 11:12

TROODON


1 Answers

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?.

like image 93
hakre Avatar answered Oct 17 '22 17:10

hakre