PHP - 打印对象的所有属性 [英] PHP - print all properties of an object

查看:313
本文介绍了PHP - 打印对象的所有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php页面中有一个未知的对象。



如何打印/回显它,所以我可以看到它有什么属性/值?



功能怎么样?有没有办法知道对象有什么功能?

解决方案

 <?php var_dump(obj)?> 

 <?php print_r(obj)?> 

这些与您用于数组的相同。



这些将使用PHP 5显示对象的受保护和私有属性。静态类成员将不会按照手册显示。



如果您想知道成员方法可以使用 get_class_methods()

  $ class_methods = get_class_methods('myclass'); 
//或
$ class_methods = get_class_methods(new myclass());
foreach($ class_methods as $ method_name)
{
echo$ method_name< br />;
}

相关内容:



get_object_vars()



get_class_vars()



get_class ()< - 为实例名称


I have an unknown object in php page.

How can I print/echo it, so I can see what properties/values do it have?

What about functions? Is there any way to know what functions an object have?

解决方案

<?php var_dump(obj) ?>

or

<?php print_r(obj) ?>

These are the same things you use for arrays too.

These will show protected and private properties of objects with PHP 5. Static class members will not be shown according to the manual.

If you want to know the member methods you can use get_class_methods():

$class_methods = get_class_methods('myclass');
// or
$class_methods = get_class_methods(new myclass());
foreach ($class_methods as $method_name) 
{
    echo "$method_name<br/>";
}

Related stuff:

get_object_vars()

get_class_vars()

get_class() <-- for the name of the instance

这篇关于PHP - 打印对象的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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