blob: 141f7b7a0f66b0c7876f51a59a24ce523482776c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<?php
abstract class Polygon {
protected $sides = 0;
abstract protected function area();
public function getSidesNum() {
return $this->sides;
}
}
class Triangle extends Polygon {
private $width = 0;
private $height = 0;
function __construct($w, $h) {
/* parent::__construct(); perhaps abstract classes do not have a ctor */
$this->width = $w;
$this->height = $h;
$this->sides = 3;
}
public function area() {
return $this->width * $this->height * 1/2;
}
}
$rightTri = new Triangle(4,4);
echo "area: {$rightTri->area()}, sides: {$rightTri->getSidesNum()}" . PHP_EOL;
|