查看PHP类实例(对象)以查看其所有可用的公共属性和方法的最佳方法是什么? [英] What is the best way to look inside a PHP class instance (object) to see all of its available public properties and methods?

查看:219
本文介绍了查看PHP类实例(对象)以查看其所有可用的公共属性和方法的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,无论如何,这里还是新手问题,

Sorry, newbie question here but anyways,

我正在尝试使用Google Data API来处理某些Google Spreadsheets,并且正在尝试使用var_dump查看我从其API调用接收的对象的结构。我尝试使用var_dump,但并没有达到我的期望。它显示给我的大多数属性都显示为受保护的,如下所示:

I'm trying to use the Google Data API to work with some Google Spreadsheets and I'm trying to use var_dump to look at the structure of the objects I'm receiving from its API calls. I tried using var_dump but it's not giving me what I expect. Most of the properties that it shows me show up as protected like this:

...

["_entryClassName:protected"]
...

,我尝试查看有关如何访问对象属性以及可以使用属性访问运算符(->)实际访问的属性的示例,我什至没有在var_dump输出中看到它们。

and I've tried looking at examples of how the objects properties are being accessed and for the properties that I can actually access with the property access operator (->) I don't even see them in the var_dump output.

所以,我真的很困惑,我想知道让我知道类实例的公共属性和方法是什么的最佳方法是什么?

So, I'm really confused and I was wondering what is the best way for me to know what are the public properties and methods of my class instance and how many of them are there?

谢谢您的帮助。

推荐答案

我想您想要PHP的 ReflectionClass ,它在运行时返回有关类定义的信息。

I think you want PHP's ReflectionClass which returns information about a class definition at runtime.

getMethods 函数接受参数以确定是否应返回有关 private 受保护的 public , static 方法等。尽管如php.net所述,

The getMethods function for example accepts parameters to determine whether it should return information about private, protected, public, static methods etc. Although as it says on php.net,


该函数当前未记录在
中;只有其参数列表可用

This function is currently not documented; only its argument list is available.

我不确定 ReflectionClass 文档是,但这使我认为您可能希望准备一些破解来实现所需的功能。

I'm not sure how full the rest of the ReflectionClass documentation is, but this makes me think you may want to get ready for a bit of hacking around to achieve exactly what you want.

这篇关于查看PHP类实例(对象)以查看其所有可用的公共属性和方法的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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