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($height); parent::setHeight($height); } } 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
Fatal error: Uncaught Error: Using $this when not in object context in /in/dLloq:51 Stack trace: #0 /in/dLloq(61): setWidthAndReturnArea(Object(Cube), 4) #1 {main} thrown in /in/dLloq on line 51
Process exited with code 255.
Output for 5.0.0 - 5.6.28
Fatal error: Using $this when not in object context in /in/dLloq 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/dLloq 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/dLloq on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/dLloq on line 3
Process exited with code 255.