I want to have a static method in a parent class that creates instances of whatever subclass i call this method on.
An example to make this more clear:
class parent { public static method make_objects($conditions){ for (...){ // here i want to create an instance // of whatever subclass i am calling make_objects on // based on certain $conditions } } } class sub extends parent{ ... } $objects = sub::make_objects($some_conditions);
As of php 5.3 you can use the static keyword for this
prints
edit: another (similar) example
prints
make the parent class an abstract class and make the parent method also an abstract
Umm, wouldn't that be:
I think you want something like this:
Now you can create an instance like this:
or
But why would you want all the sub classes to extend the parent? Shouldn't you much rather have a parent for your models (sub classes) and then a factory class, that creates the instances for this models depending on the conditions given?