Psuedo-polymorphism
Posted: Sun Jun 05, 2005 7:23 pm
Hi,
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?
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
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?
Code: Select all
$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();Edit: Sorry I know it's the wrong forum!