From 06dbe9737b7dfc9e6d6e1df00e7d2050b48e4d4f Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 25 Jul 2015 14:03:01 -0400 Subject: [PATCH] Initial inheritance bits --- c&s20150725/inheritance.php | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 c&s20150725/inheritance.php diff --git a/c&s20150725/inheritance.php b/c&s20150725/inheritance.php new file mode 100644 index 0000000..dcbf31a --- /dev/null +++ b/c&s20150725/inheritance.php @@ -0,0 +1,44 @@ +isRunning = true; + return $this->name . ' is running'; + } +} + +class Dog extends Pet { + protected $currentChaseTarget; + + public function chase(Pet $chaseTarget) + { + $this->isRunning = true; + $this->currentChaseTarget = $chaseTarget; + $this->currentChaseTarget->run(); + + return $this->name . ' is chasing ' . $chaseTarget->name; + } +} + +$cat = new Pet(); +$cat->name = 'Felix'; + +var_dump($cat); + +$cat->run(); + +var_dump($cat); + +$dog = new Dog(); +$dog->name = 'Fido'; + +var_dump($dog); + +var_dump($dog->chase($cat)); + +var_dump($dog); +var_dump($cat);