<?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';
}
Warning: Undefined variable $width in /in/hNtPq on line 42
Warning: 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.
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 7.3.32 - 7.3.33
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.
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.