How to know what class is an object instance of? (

2019-01-29 07:23发布

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

标签: php oop
2条回答
SAY GOODBYE
2楼-- · 2019-01-29 08:04

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

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

查看更多
乱世女痞
3楼-- · 2019-01-29 08:08

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.

查看更多
登录 后发表回答