3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Food { public function consume() { } } class AnimalFood extends Food { } abstract class Animal { protected string $name; public function __construct(string $name) { $this->name = $name; } abstract public function speak(); public function eat(AnimalFood $food) { $food->consume(); } } class Dog extends Animal { public function speak() { echo $this->name . " barks"; } /* * The dog doesn't care if it's animal food, it'll eat ANY food */ public function eat(Food $food) { $food->consume(); } } class Cat extends Animal { public function speak() { echo $this->name . " meows"; } } interface AnimalShelter { public static function adopt(string $name): Animal; } class CatShelter implements AnimalShelter { public static function adopt(string $name): Cat { return new Cat($name); } } class DogShelter implements AnimalShelter { public static function adopt(string $name): Dog { return new Dog($name); } } $kitty = CatShelter::adopt("Ricky"); $kitty->speak(); echo "\n"; $doggy = DogShelter::adopt("Mavrick"); $doggy->speak();
Output for git.master, git.master_jit, rfc.property-hooks
Ricky meows Mavrick barks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
95.21 ms | 405 KiB | 5 Q