summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--oo/abstract.php27
-rw-r--r--oo/magic_methods.php16
-rw-r--r--oo/singleton.php3
-rw-r--r--scratch.php7
4 files changed, 53 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;
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 @@
+<?php
+
+abstract class Base {
+ protected $arr;
+
+ function __construct() {
+ echo 'dispatching ctor';
+ $this->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 @@
+<?php
+
+
diff --git a/scratch.php b/scratch.php
new file mode 100644
index 0000000..9c47450
--- /dev/null
+++ b/scratch.php
@@ -0,0 +1,7 @@
+<?php
+
+function foo() {
+ echo "hello, world!" . PHP_EOL;
+}
+
+call_user_func("foo");