0

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.

3 Answers 3

2
$reflectedNode = new \ReflectionClass($obj);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for all the replies everyone. Really appreciate the quick responses.
1

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.

Comments

1

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

$reflectedNode = new \ReflectionClass($obj);

Read the manual.

Comments

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.