user1024419
user1024419

Reputation: 3

php namespace issue

Relative newbie to php, running into an issue with namespaces. Inside my own class within a custom namespace I am trying to call the native php ReflectionClass, but it is telling me that it can not find it within my own namespace. How do I call the global ReflectionClass?

$reflectedNode = new ReflectionClass($obj);

Thanks in advance.

Upvotes: 0

Views: 160

Answers (3)

Francis Avila
Francis Avila

Reputation: 31651

Prefix your name with a "\", like so:

$reflectedNode = new \ReflectionClass($obj);

Read the manual.

Upvotes: 1

Polynomial
Polynomial

Reputation: 28346

The PHP documentation has an FAQ that covers this:

http://www.php.net/manual/en/language.namespaces.faq.php#language.namespaces.faq.globalclass

Essentially you just prefix the global class name with a backslash (\) character.

Upvotes: 1

Layke
Layke

Reputation: 53206

$reflectedNode = new \ReflectionClass($obj);

Upvotes: 2

Related Questions