tags:

views:

80

answers:

3

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?

+6  A: 
<?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

Peter Ajtai
What about functions? Is there any way to know what functions an object have?
stacker
I added in get_class_methods() above.
Peter Ajtai
+2  A: 
var_dump($obj); 

If you want more info you can use a ReflectionClass:

http://www.phpro.org/manual/language.oop5.reflection.html

meder
+1  A: 

I really like dBug. I usually use var_dump() for scalars (int, string, boolean, etc.) and dBug for arrays and objects.

Object screenshot from the official site:

alt text

Adam Backstrom