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

余生长醉 提交于 2019-11-29 17:24:24

问题


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

回答1:


Try with

\Database::request();

Also see Namespace Basics Example 1 in the PHP Manual



来源:https://stackoverflow.com/questions/6579040/calling-a-static-method-from-a-class-in-another-namespace-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!