Is there anyway to create a class object type based on var value ?
Example for what I would like to do:
Say I have some dozens of classes: ClassA, ClassB and ClassC,... that are all extends of ClassBasic class. So they have the same interface function doOperation()
, but different internal implementation.
// the variable contains the name of the desired class type.
$TypeToCreate = "ClassC";
// create the desired type of class
$ClassObj = new $TypeToCreate;
// do some operation of the created class.
$ClassObj->doOperation();