summaryrefslogtreecommitdiffstats
path: root/oo/abstract.php
diff options
context:
space:
mode:
authorKyle Kaminski <kyle@xenomedia.com>2014-04-09 22:02:09 -0500
committerKyle Kaminski <kyle@xenomedia.com>2014-04-09 22:02:09 -0500
commitaf5272c6784050a97ce968d067274b86099fc3af (patch)
tree916d087495e8e67647597931ddb0fed79aa58544 /oo/abstract.php
parent55cfec6918fca9d3790ec8ab231d0178349fe2fa (diff)
downloadphpsandbox-af5272c6784050a97ce968d067274b86099fc3af.tar.gz
phpsandbox-af5272c6784050a97ce968d067274b86099fc3af.tar.bz2
phpsandbox-af5272c6784050a97ce968d067274b86099fc3af.zip
some oo concepts
Diffstat (limited to 'oo/abstract.php')
-rw-r--r--oo/abstract.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/oo/abstract.php b/oo/abstract.php
new file mode 100644
index 0000000..141f7b7
--- /dev/null
+++ b/oo/abstract.php
@@ -0,0 +1,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;