From af5272c6784050a97ce968d067274b86099fc3af Mon Sep 17 00:00:00 2001 From: Kyle Kaminski Date: Wed, 9 Apr 2014 22:02:09 -0500 Subject: some oo concepts --- oo/abstract.php | 27 +++++++++++++++++++++++++++ oo/magic_methods.php | 16 ++++++++++++++++ oo/singleton.php | 3 +++ scratch.php | 7 +++++++ 4 files changed, 53 insertions(+) create mode 100644 oo/abstract.php create mode 100644 oo/magic_methods.php create mode 100644 oo/singleton.php create mode 100644 scratch.php 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 @@ +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; diff --git a/oo/magic_methods.php b/oo/magic_methods.php new file mode 100644 index 0000000..8d9da79 --- /dev/null +++ b/oo/magic_methods.php @@ -0,0 +1,16 @@ +arr = array(); + } + + abstract protected function foo(); +} + +class Derived extends Base { + +} \ No newline at end of file diff --git a/oo/singleton.php b/oo/singleton.php new file mode 100644 index 0000000..50cce95 --- /dev/null +++ b/oo/singleton.php @@ -0,0 +1,3 @@ +