3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Animal { protected string $name; public function __construct(string $name) { $this->name = $name; } abstract public function speak(); } class Cat extends Animal { public function speak() { echo $this->name . " meows"; } } // However, covariant return types cannot return a more broad type interface AnimalShelter { public function adopt(string $name): Cat; } class CatShelter implements AnimalShelter { public function adopt(string $name): Animal { return new Animal($name); } } $kitty = (new CatShelter)->adopt("Ricky"); $kitty->speak();

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
163.84 ms | 2144 KiB | 10 Q