Hi
Is there any way to extract the names of variables in a class?
Prehaps as an array or something?
My idea was to have a function in the class class->getVariableNames()
function getVariableNames()
{
return $this->FUNCTION_TO_GET_VARIABLE_NAMES_THAT_I_DONT_KNOW();
}
or if there is a function that could do it outside the class and still get all the private variables etc.
One way that I thought of was to have a class read the file it is written in and parse out the names myself, but it would be heck of a lot better if a function exists.
/ Daniel
p.s.
If you wonder I would use this to insert data into a database and using a generic way to be able to insert data from any type of class I make.
I know I could serialize the class and put it in a table, but the data must be readeable from other places so that's not an option.
Thanx in advanceThe reflection API provides access to pretty much all the bits and pieces that a class is made up of (use the ReflectionClass class to get an array of ReflectionProperty objects).
Is there any way to extract the names of variables in a class?
Prehaps as an array or something?
My idea was to have a function in the class class->getVariableNames()
function getVariableNames()
{
return $this->FUNCTION_TO_GET_VARIABLE_NAMES_THAT_I_DONT_KNOW();
}
or if there is a function that could do it outside the class and still get all the private variables etc.
One way that I thought of was to have a class read the file it is written in and parse out the names myself, but it would be heck of a lot better if a function exists.
/ Daniel
p.s.
If you wonder I would use this to insert data into a database and using a generic way to be able to insert data from any type of class I make.
I know I could serialize the class and put it in a table, but the data must be readeable from other places so that's not an option.
Thanx in advanceThe reflection API provides access to pretty much all the bits and pieces that a class is made up of (use the ReflectionClass class to get an array of ReflectionProperty objects).