Thomas Joulin
Thomas Joulin

Reputation: 6650

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();
        }
    }
}

Upvotes: 14

Views: 11655

Answers (1)

Gordon
Gordon

Reputation: 317207

Try with

\Database::request();

Also see Namespace Basics Example 1 in the PHP Manual

Upvotes: 22

Related Questions