Polymorphism in PHP
Në shqip: Polimorfizmi në PHP
ShpjegimiSQ
Me interface ose klasë abstrakte, mund të trajtosh objekte të ndryshme njësoj: një varg Forma me rrathë e katrorë, ku $f->siperfaqja() thërret versionin e duhur për secilin.
EnglishEN
With an interface or abstract class, you can treat different objects the same way: an array of Shapes with circles and squares, where $s->area() calls the right version for each.
Si ta mendosh
Si „luaj!“ për instrumente të ndryshme.
Lexoje në anglisht
Like saying “play!” to different instruments.
Shembull kodiphp
foreach ($format as $f) {
echo $f->siperfaqja(), "\n";
}