[ACCEPTED]-PHP's function to list all objects's properties and methods-oop

Accepted answer
Score: 17

PHP5 includes a complete Reflection API for going beyond 1 what the older get_class_methods and get_object_vars can do.

Score: 14

You can use the Reflection API's ReflectionClass::getProperties and ReflectionClass::getMethods methods 11 to do this (although the API doesn't seem 10 to be very well documented). Note that PHP 9 reflection only reflects compile time information, not 8 runtime objects. If you want runtime objects 7 to also be included in your query results, best 6 to use the get_object_vars, get_class_vars and get_class_methods functions. The difference 5 between get_object_vars and get_class_vars is that the former gets you 4 all the variables on a given object (including 3 those dynamically added at runtime), while 2 the latter gives you only those which have 1 been explicitly declared in the class.

Score: 11
Reflection::export(new ReflectionObject($Yourobject));


Score: 7

You can use get_object_vars to list object variables and 1 get_class_methods to list the methods of a given class.

Score: 0

If you want to go deeper, and also get the 2 private var of the object, you can use closure 1 for that. like:

$sweetsThief = function ($obj) {
  return get_object_vars($obj);

$sweetsThief = \Closure::bind($sweetsThief, null, $myobj);


More Related questions