There are for example the main class and classes that extend it:
class mainClass { public static function some_function() { $obj = new mainClass(); $obj->property1 = 'Value of property1'; $obj->property2 = 'Value of property2'; return $obj; } } $mainObj = new mainClass(); class addedClass1 extends mainClass { public static function some_function() { $obj = mainClass::some_function(); $obj->property1 = 'Overrided value of property1'; return $obj; } } class addedClass2 extends mainClass { public static function some_function() { $obj = mainClass::some_function(); $obj->property2 = 'Overrided value of property2'; return $obj; } } $arrayOfClasses = ['addedClass1','addedClass2']; foreach($arrayOfClasses as $class) { $mainObj = new $class(); } echo $mainObj->some_function()->property1 .'<br>'; echo $mainObj->some_function()->property2; In this case, the class addedClass2 rewrites $obj->property2 as it should, but addedClass1 no longer overwrites $obj->property1
Those. now I get:
Value of property1 Overrided value of property2 And you need:
Overrided value of property1 Overrided value of property2 How to make all classes connect and overwrite each of its own separate property?
ps. addedClass will actually connect everything from a separate directory, so neither their names nor the total number are known, these two are for example only