I've got a small problem I want to sovle in PHP4 using classes to sort of emulate polymorphism. I've got several similar classes which all have a display() function in them. What I want to do is create an array of these objects and be able to loop through each of them calling the display() function. Is it possible to do something like this?
$ob1 = new Object1();
$ob2 = new Object2();
$ob3 = new Object3();
$object_array = array($ob1, $ob2, $ob3);
for($i = 0; $i < count($object_array); $i++)
$object_array[$i]->display();
I know this is possible via interfaces and such in PHP5 but can this be done in PHP4?
Edit: Sorry I know it's the wrong forum! I meant to stick this in Code
Hmm, not sure if I understand your reply in relation to my question. I don't neccesarily want to extract any information from the objects themselves. What I want to do is create an array of 3 different objects which all have the same function (display()) in them. Then I want to loop through all the objects and call display().