PHP Root namespace

I have one file where I need to specify classes in multiple namespaces, for example:

<?php

namespace library;

class ClassInLib {
   ...
}

namespace \; //Switch to root namespace

class ClassInRoot {
   ...
}

      

The above code has a syntax error in namespace \;

. How can I go from namespace library

to root namespace?

Why I need this: I need to mock a bunch of classes during unit testing, and I don't think these very short mock classes justify having separate files.

+3


source to share


1 answer


namespace 
{ 
    class RootClass
    {

        function whatever();
    }
}
namespace Symfony\Component\DependencyInjection
{
    interface ContainerAwareInterface
    {

        function setContainer(ContainerInterface $container = null);
    }
}

      

http://www.php.net/manual/en/language.namespaces.definitionmultiple.php



There is a good chance that you decide to use separate files anyway.

+5


source







All Articles