Skip to content

Instantly share code, notes, and snippets.

@kamrankr
Last active May 22, 2023 22:16
Show Gist options
  • Save kamrankr/8b7101fcf4d537a5c43c to your computer and use it in GitHub Desktop.
Save kamrankr/8b7101fcf4d537a5c43c to your computer and use it in GitHub Desktop.
simplest Polymorphism example in Php
<?php
/* simplest Polymorphism example in Php */
abstract class Animal
{
static function makeSound(Animal $animal)
{
return $animal->getsound();
}
}
class dog extends Animal
{
function getsound()
{
return "Woof Woof";
}
}
class cat extends Animal
{
function getsound()
{
return "Meow Meow";
}
}
echo Animal::makeSound(new cat);
echo Animal::makeSound(new dog);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment