wow, that's a lot of ranting without actually answering his question.
$vars = get_class_vars('Class');
// or
$vars = get_class_vars(new Class());
There are more in-depth methods (see Reflection in the PHP manual) but this will get the job done
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
finally! I actually given up on this thread because I thought no one would come inside a thread so many replies.
thanks for the insight ShawnCPlus. Unfortunately, that function doesn't do what I want. because it does not accept an object. maybe I phrased my question wrongly.
$object = new MyClass();
// after some funny operations
// that dynamically creates more member variables
$var = get_class_variables($object); //error.
I'll look up "Reflection" on PHP first. thanks!!
it's actually get_class_vars, not get_class_variables.
If that still doesn't work try
$var = get_class_vars(get_class($object));
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
If you're doing a container of sorts where you dynamically add variables and get them you might want something like this.
class Container
{
private $holder;
public function __get($key)
{
return isset($this->holder[$key]) ? $this->holder[$key] : false;
}
public function __set($key, $value)
{
$this->holder[$key] = $value;
}
public function toArray()
{
return print_r($this->holder, true);
}
}
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
Oh.... so that works... ok, i learnt something new today. thanks!
but for me to use that will mean breaking up old code and base classes... =(
I think I can proceed from here now. thanks alot for your help.
Well you don't have to use that. The basic concept to learn is that when using dynamic variables with __get and __set its usually better practice to use a holder variable so you have better separation of class variables and dynamic variables.
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268