简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM