3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class ShapeFactory { public function __construct($type) { $shape = null; switch ($type){ case 'rectangle': $shape = new RectagleShape; break; case 'square': $shape = new SquareShape; break; default: return 'No such file'; } return $shape->render(); } } interface Shape { public function render(); } class Square implements Shape { public $name = 'square'; public function render() { return $this->name; } } class Rectangle implements Shape { public $name = 'rectangle'; public function render() { return $this->name; } } $test = new Factory('rectangle');
based on Fsb3R
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Class 'Factory' not found in /in/fvGZp:49 Stack trace: #0 {main} thrown in /in/fvGZp on line 49
Process exited with code 255.
Output for 5.3.19 - 5.6.28
Fatal error: Class 'Factory' not found in /in/fvGZp on line 49
Process exited with code 255.