Answer the question
In order to leave comments, you need to log in
How to create a global class inside namespace?
Namespace ABC is declared at the beginning of the file, how can a class be created in the global namespace?
namespace ABC;
//этот класс должен быть внутри ABC
class A {
}
//а этот класс должен быть глобальным
class B {
}
Answer the question
In order to leave comments, you need to log in
Follow the PSR and move the class declaration to a separate file in the expected PSR-4 (or PSR-0) path.
But if you suddenly want
namespace ABC {
//этот класс должен быть внутри ABC
class A {
public static function nspc()
{
return __NAMESPACE__;
}
}
}
namespace {
//а этот класс должен быть глобальным
class B {
public static function nspc()
{
return __NAMESPACE__;
}
}
class C extends ABC\A {
}
echo ABC\A::nspc();
echo '<br>----------------<br>';
echo B::nspc();
echo '<br>----------------<br>';
echo C::nspc();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question