What is the best way to look at an instance (object) of a PHP class to see all the public properties and methods available to it?

Sorry, newbie here, but anyway,

I am trying to use the Google Data API to work with some Google tables, and I am trying to use var_dump to view the structure of the objects that I get from API calls. I tried using var_dump, but that did not give me what I expect. Most of the properties that he shows me appear as protected as follows:

... ["_entryClassName:protected"] ... 

and I tried to look at examples of how the properties of objects will be executed, and for the properties that I can get using the property access operator (->), I don’t even see them in the var_dump output.

So, I'm really confused, and I was wondering, how do I better find out which public properties and methods of my class instance and how many of them are?

Thanks for any help in advance.

+1
object reflection debugging oop php
source share
5 answers

I think you need a PHP ReflectionClass that returns class definition information at runtime.

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

This feature is currently not documented; only his argument list is available.

I'm not sure how complete the rest of the ReflectionClass documentation is, but it makes me think you might want to hack a bit to achieve exactly what you want.

+4
source share

I would suggest using an IDE with a debugger for this to work.

However, if you want to do this in a complicated way, you can use reflection, and especially ReflectionClass , which has a number of useful methods:

http://www.php.net/manual/en/class.reflectionclass.php

Example:

 $c = new ReflectionClass( get_class($myObject) ); $properties = $c->getProperties( ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED ); foreach ($properties as $property) { echo $property->getName() . "\n"; } 
+2
source share

You can find the official API documentation in the Zend Framework API documentation (because of its part): http://framework.zend.com/apidoc/core/ (in the Zend_Gdata package)

As a side element: ZF only implements access methods ( get*() and set*() ) instead of public properties.

0
source share

See get_class_methods in php manual.

0
source share

You can use:

See an example using the first method:

 <?php class Test { public $public_property = 'public_property'; protected $protected_property = 'protected_property'; private $private_property = 'private_property'; public function public_method() {} protected function protected_method() {} private function private_method() {} } $instance = new Test(); // Show public methods print_r(get_class_methods($instance)); // Show public properties print_r(get_object_vars($instance)); 
0
source share

All Articles