2

If I have an object, how can I know the details of the object. Like the file in which it is defined, its methods, properties etc.

2 Answers 2

6

You can use PHP reflection functionalities

$class = new ReflectionClass('MyClass'); echo $class->getFileName()."\n"; var_dump($class->getMethods()); var_dump($class->getProperties()); 

Edit:

ReflectionClass is used on classes and ReflectionObject on objects.

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

Comments

4

Reflection

If you want something simpler, there's get_class_methods(), get_object_methods(), get_class_vars(), get_object_vars(), etc.

3 Comments

thanks.. i was looking for get_object_methods and get_object_vars.. I couldn't use Reflection classes, since I want the info based on the object i have in hand..
No get_object_methods() though.
If you somehow end-up here in 2025 or beyond... yes, get_object_methods() seems to have been removed, but get_class_methods() is still available and works for both class and object types: php.net/manual/en/function.get-class-methods.php

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.