如何获取对象或类名? [英] How to get the object or class name?
本文介绍了如何获取对象或类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在,我有这个代码,其中 $obj_arr
可能包含数组和一个对象.
Right now, I have this code where $obj_arr
maybe contain array and an object.
$obj_temp = array ($obj_identity, $arr_user, $obj_locale, $arr_query);
foreach ($obj_temp as $maybe_arr) {
if (is_array($maybe_arr)) :
$name = (string) key($maybe_arr);
if (is_object($maybe_arr)) :
???? // how to retrieve a class name ?
endif;
$obj_arr[$name] = $maybe_arr;
}
obj_will_be_extract($obj_arr);
function obj_will_be_extract($obj_arr) {
extract($obj_arr);
//Do the rest
}
我需要创建一个由对象和数组组合而成的数组.因为我需要提取它,那么如何获取对象名称?
I need to create an array consist of combination of objects and arrays. Cause I need to extract it, then how to get an object name?
推荐答案
使用 get_class
获取对象的类名.
Use get_class
to get the class name of an object.
这篇关于如何获取对象或类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文