当前位置: 动力学知识库 > 问答 > 编程问答 >

Calling a static method from a class in another namespace in PHP

问题描述:

This code bellow gives me this error : Class 'MyNamespace\Database' not found. How do I reference a class that belongs to no namespace, from inside one ?

Class Database

{

public function request()

{

}

}

namespace MyNamespace

{

class MyClass

{

public function myFuction()

{

Database::request();

}

}

}

网友答案:

Try with

\Database::request();

Also see Namespace Basics Example 1 in the PHP Manual

分享给朋友:
您可能感兴趣的文章:
随机阅读: