I'm trying to make a class that takes some unspecified data from a database query (passed to my class as an array) and turns it into a PHP object with properties that are created dynamically from the data passed to it.
Like so:
class myLibrary_Item extends myLibrary
{
private function __construct($vars)
{
foreach($vars as $var => $val)
{
$this->$var => $val;
}
}
private function __set($var, $val)
{
$this->$var => $val;
}
private function __get($var)
{
return $this->$var;
}
}
$myArray = array(
'firstName' => 'Joe',
'lastName' => 'Carrington'
);
$myObject = new myLibrary_Item($myArray)
echo $myObject->firstName;
//Hopefully will output Joe
So, my question, is this a good idea at all? Am I missing the point of OOP here? Should I learn about PDO instead? It seems like this could be a big help, but I don't want to hammer out the bugs if this is going to bite me in the butt later.