Tutorial :Any way to enumerate class members?



Question:

I have a class instance, and I want to enumerate its members.

How can this be done?


Solution:1

You can use get_class_vars(), or get_object_vars() if you are looking at an instance.

You could also use reflection.


Solution:2

Take a look at PHP's reflection API

$r = new ReflectionClass("domdocument");  foreach ($r->getProperties() as $name => $prop) { ... }  foreach ($r->getMethods() as $name => $method) { ... }  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »