Looking to see if there is any way to implement the kind of functionality of the __get()
magic method, but when trying to instantiate a new class.
My goal is to have
$foo = new Cat();
Ultimately result in the creation of a generic object, i.e.
new Mammal('Cat');
Such that $foo
would be an instance of the class Mammal
, with the called class name ('Cat'
) passed as an argument to Mammal
's constructor.
Note: The end game I have in mind, for those familiar with Lithium or CakePHP, is to avoid having to define a whole bunch of classes for each different database table. If I did, most would simply be empty, the basic CRUD operations being all that is necessary. Plus, all those includes and class definitions can't be great for overhead. My idea would be to use a single "Model" class to handle most of the generic functions, and I could always create subclasses if I needed more advanced functionality for a specific database table.