romaninsh
romaninsh

Reputation: 10674

Extending un-namespaced class from a namespace

I have the following legacy file (can't edit):

class Test {
    public $abc=1;
}

I need to extend this class from a name-spaced file:

use mynamespace;
class MyClass extends Test {
}

However my auto-load function attempts to include mynamespace\Test. How to specify that un-namespaced version of Test should be used?

Upvotes: 2

Views: 91

Answers (2)

Tom
Tom

Reputation: 3063

Try this:

class MyClass extends \Test {
}

Upvotes: 1

David Harkness
David Harkness

Reputation: 36562

Prefix the class name with a \:

class MyClass extends \Test {
    ...
}

From the manual on namespaces: "Note that to access any global class, function or constant, a fully qualified name can be used, such as \strlen() or \Exception or \INI_ALL."

Upvotes: 1

Related Questions