14

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();
        }
    }
}
2
  • I believe this can be solved in C++ doing ::Database::request(), but I tried that with no success in PHP ;) Commented Jul 5, 2011 at 7:10
  • 1
    Indeed; the solution is equivalent, but in PHP the namespace "scope resolution operator" of sorts is \ , not ::. Commented Jul 6, 2011 at 9:06

1 Answer 1

22

Try with

\Database::request();

Also see Namespace Basics Example 1 in the PHP Manual

Sign up to request clarification or add additional context in comments.

1 Comment

Wow that was fast ! Thanks, it works, and it's even uglier than its C++ counterpart :p

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.