<?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 $rectangle->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';
}