Content deleted Content added
m ce lead |
|||
Line 385:
{
public function makeSound()
{
echo "Woof...\n";
}
}
Line 393:
{
public function makeSound()
{
echo "Meowww...\n";
}
}
Line 401:
{
public function makeSound()
{
// silence...
}
Line 407:
$animalType = 'elephant';
switch($animalType) {▼
function makeAnimalFromAnimalType(string $animalType): Animal
{
$animal = new Dog();▼
▲ switch($animalType) {
case '
return new Cat();
}
}
function animalMakeSound(Animal $animal): void
{
}
foreach ([
makeAnimalFromAnimalType('dog'),
makeAnimalFromAnimalType('NullAnimal'),
makeAnimalFromAnimalType('cat'),
] as $animal) {
// That's also reduce null handling code
animalMakeSound($animal);
}
▲$animal->makeSound(); // ..the null animal makes no sound
</syntaxhighlight>
|