views:

467

answers:

2

How would I list all the public variables in an instantiated Object given that we do not know the variable names in the first place?

Scenario
A class may have a function declared like:

function addVar($name, $val) {
    $this->$name = $val;
}

I want a list of $names that were ever added to the object instance dynamically.

+5  A: 

get_object_vars() should do the trick.

Chad Birch
A: 

Additionally, I would recommend you look into PHP's Reflection capabilities.

Jordan S. Jones