3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php interface Shape { public function getArea(); } class Rectangle implements Shape { private $width; private $height; public function setWidth($width) { $this->width = $width; } public function setHeight($height) { $this->height = $height; } public function getWidth() { return $this->width; } public function getHeight() { return $height->height; } public function getArea() { return $this->height * $this->width; } } class Cube extends Rectangle { public function setWidth($width) { parent::setWidth($width); parent::setHeight($width); } public function setHeight($height) { parent::setWidth($width); parent::setHeight($width); } } function setWidthAndReturnArea(Rectangle $rectangle, $width) { $rectangle->setWidth($width); return $this->getArea(); } $width = 2; $height = 2; $cube = new Cube(); $cube->setWidth($width); $cube->setHeight($height); $area = setWidthAndReturnArea($cube, $width = 4); if ($area == $width * $height) { echo '$cube gedraagt zich als een Rectangle'; } else { echo '$cube gedraagt zich niet als een Rectangle'; }
Output for 7.0.0 - 7.1.0
Notice: Undefined variable: width in /in/hNtPq on line 42 Notice: Undefined variable: width in /in/hNtPq on line 43 Fatal error: Uncaught Error: Using $this when not in object context in /in/hNtPq:51 Stack trace: #0 /in/hNtPq(61): setWidthAndReturnArea(Object(Cube), 4) #1 {main} thrown in /in/hNtPq on line 51
Process exited with code 255.
Output for hhvm-3.12.0
Notice: Undefined variable: width in /in/hNtPq on line 42 Notice: Undefined variable: width in /in/hNtPq on line 43 Notice: Undefined variable: this in /in/hNtPq on line 51 Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function getArea() on a non-object (null)' in /in/hNtPq:51 Stack trace: #0 /in/hNtPq(61): setWidthAndReturnArea() #1 {main}
Process exited with code 255.
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.0.4 - 5.6.28
Notice: Undefined variable: width in /in/hNtPq on line 42 Notice: Undefined variable: width in /in/hNtPq on line 43 Fatal error: Using $this when not in object context in /in/hNtPq on line 51
Process exited with code 255.
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: width in /in/hNtPq on line 42 Notice: Undefined variable: width in /in/hNtPq on line 43 Fatal error: Using $this when not in object context in /in/hNtPq on line 51
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING in /in/hNtPq on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING in /in/hNtPq on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/hNtPq on line 3
Process exited with code 255.