3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ShapeFactory { public function __construct($type) { $shape = null; switch ($type){ case 'rectangle': $shape = new RectangleShape; break; case 'square': $shape = new SquareShape; break; default: return 'No such file'; } print_r($shape); return $shape->render(); } } interface Shape { public function render(); } class SquareShape implements Shape { public $name = 'square'; public function render() { return $this->name; } } class RectangleShape implements Shape { public $name = 'rectangle'; public function render() { echo $this->name; return $this->name; } } $test = new ShapeFactory('rectangle'); echo $test;

preferences:
44.05 ms | 402 KiB | 5 Q