如何获得的对象或类的名字吗? [英] How to get the object or class name?

查看:91
本文介绍了如何获得的对象或类的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我有这个code其中 $ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆