In PHP 5, how do I figure out what class is an object instance of? I know I can compare with the "instanceof" operator, but I don't seem to find how to proceed when the Class name is unknown.
Thanks in advance! :)
In PHP 5, how do I figure out what class is an object instance of? I know I can compare with the "instanceof" operator, but I don't seem to find how to proceed when the Class name is unknown.
Thanks in advance! :)
get_class(...) will tell you the class of which an object is an instance.
You mean, you want to find all objects that are of a certain class?
The simplest way I can think of is to go through each variable returned by get_defined_vars()
and run an instanceof
on each of them. Can be hugely expensive speed and memory wise, though.