3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ToolSetFactory { public function createGeneral(): General; public function createArrows(): Arrows; public function createFlowchart(): Flowchart; public function createUML(): UML; public function createEntityRelation(): EntityRelation; public function createMisc(): Misc; } class BasicToolSetFactory implements ToolSetFactory { public function createGeneral(): General { return new GeneralProduct(); } public function createArrows(): Arrows { return new ArrowsProduct(); } public function createFlowchart(): Flowchart { return new NullFlowchartProduct(); } public function createUML(): UML { return new NullUMLProduct(); } public function createEntityRelation(): EntityRelation { return new NullEntityRelationProduct(); } public function createMisc(): Misc { return new MiscProduct(); } } // Interfaces interface Drawable { public function draw(): void; } interface General extends Drawable {} interface Arrows extends Drawable {} interface Flowchart extends Drawable {} interface UML extends Drawable {} interface EntityRelation extends Drawable {} interface Misc extends Drawable {} // Products class GeneralProduct implements General { public function draw(): void { print "Drawing general elements\n"; } // Other methods } class ArrowsProduct implements Arrows { public function draw(): void { print "Drawing arrows elements\n"; } // Other methods } class MiscProduct implements Misc { public function draw(): void { print "Drawing misc elements\n"; } // Other methods } class NullFlowchartProduct implements Flowchart { public function draw(): void { print ''; } // Other methods } class NullUMLProduct implements UML { public function draw(): void { print ''; } // Other methods } class NullEntityRelationProduct implements EntityRelation { public function draw(): void { print ''; } // Other methods } // Client code class BasicToolSet { public function createToolSet(ToolSetFactory $factory) { $general = $factory->createGeneral(); $arrows = $factory->createArrows(); $misc = $factory->createMisc(); foreach ([ $general, $arrows, $misc ] as $product) { $product->draw(); } } // other stuff } // Usage $basicToolSetFactory = new BasicToolSetFactory(); $basicToolSet = new BasicToolSet(); $basicToolSet->createToolSet($basicToolSetFactory);
Output for git.master, git.master_jit, rfc.property-hooks
Drawing general elements Drawing arrows elements Drawing misc elements

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:
26.91 ms | 405 KiB | 5 Q