How do you know which class is an instance of an object? (Php5)

In PHP 5, how can I determine which class is an instance of an object? I know that I can compare with the instanceof operator, but it seems I don’t know what to do when the class name is unknown.

Thanks in advance!:)

0
oop php
Dec 18 '09 at 14:24
source share
2 answers

get_class (...) will show you the class whose object is the instance.

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

+9
Dec 18 '09 at 14:27
source share
β€” -

Do you mean that you want to find all the objects of a particular class?

The easiest way I can think of is to go through each variable returned by get_defined_vars() and run instanceof on each of them. However, there can be very expensive speed and memory.

0
Dec 18 '09 at 14:28
source share



All Articles