[ACCEPTED]-PHP's function to list all objects's properties and methods-oop
PHP5 includes a complete Reflection API for going beyond 1 what the older get_class_methods and get_object_vars can do.
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.
Reflection::export(new ReflectionObject($Yourobject));
0
You can use get_object_vars
to list object variables and 1 get_class_methods
to list the methods of a given class.
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);
var_dump($sweetsThief($myobj));
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.