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 RectangleShape; break; case 'square': $shape = new SquareShape; break; default: echo 'No such file'; } $message = $shape->render(); echo $message; } } 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;
based on LkepY
Output for 7.1.0 - 7.2.0
rectangle Recoverable fatal error: Object of class ShapeFactory could not be converted to string in /in/avT75 on line 53
Process exited with code 255.
Output for 5.3.19 - 7.0.20
rectangle Catchable fatal error: Object of class ShapeFactory could not be converted to string in /in/avT75 on line 53
Process exited with code 255.