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 git.master, git.master_jit, rfc.property-hooks
Auto fährt Golf fährt schneller Porsche fährt am schnellsten

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:
41.03 ms | 401 KiB | 8 Q