tags:

views:

80

answers:

2

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! :)

+9  A: 

get_class(...) will tell you the class of which an object is an instance.

http://www.php.net/manual/en/function.get-class.php

Mike
add the Reflection API to the list
Gordon
How could I miss that! Thank you very much :-) that's exactly what I meant.
Danita
A: 

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.

Pekka