3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Visitor { public function visitCar(Car $car); public function visitGolf(Golf $golf); public function visitPorsche(Porsche $porsche); } interface Vehicle { public function accept(Visitor $v); } class Car implements Vehicle { public function accept(Visitor $v) { $v->visitCar($this); } } class Golf extends Car { public function accept(Visitor $v) { $v->visitGolf($this); } } class Porsche extends Car { public function accept(Visitor $v) { $v->visitPorsche($this); } } class DriveVisitor implements Visitor { public function visitCar(Car $car) { print 'Auto fährt' . PHP_EOL; } public function visitGolf(Golf $golf) { print 'Golf fährt schneller' . PHP_EOL; } public function visitPorsche(Porsche $porsche) { print 'Porsche fährt am schnellsten' . PHP_EOL; } } $c = new Car(); $g = new Golf(); $p = new Porsche(); $dv = new DriveVisitor(); $c->accept($dv); $g->accept($dv); $p->accept($dv);
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.20, 8.3.0 - 8.3.8
Auto fährt Golf fährt schneller Porsche fährt am schnellsten

preferences:
166.92 ms | 404 KiB | 185 Q