Created
May 23, 2017 21:17
-
-
Save spelcaster/e331f49d677626dd9ef410a985432d92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class A | |
{ | |
public function inheritance() | |
{ | |
return self::p(); | |
} | |
public function inheritance2() | |
{ | |
return $this->pA(); | |
} | |
protected function p() | |
{ | |
return "A"; | |
} | |
protected function pA() | |
{ | |
return "A"; | |
} | |
abstract protected function pB(); | |
abstract protected function pC(); | |
} | |
abstract class B extends A | |
{ | |
public function inheritance() | |
{ | |
return parent::inheritance() . " <- " . self::p(); | |
} | |
public function inheritance2() | |
{ | |
return parent::inheritance2() . " <- " . $this->pB(); | |
} | |
protected function p() | |
{ | |
return "B"; | |
} | |
protected function pB() | |
{ | |
return "B"; | |
} | |
} | |
class C extends B | |
{ | |
public function inheritance() | |
{ | |
return parent::inheritance() . " <- " . $this->p(); | |
} | |
public function inheritance2() | |
{ | |
return parent::inheritance2() . " <- " . $this->pC(); | |
} | |
protected function p() | |
{ | |
return "C"; | |
} | |
protected function pC() | |
{ | |
return "C"; | |
} | |
} | |
$c = new C(); | |
echo "Using ´self´: \n"; | |
echo "{$c->inheritance()} \n"; | |
echo "\n"; | |
echo "Using specific methods: \n"; | |
echo "{$c->inheritance2()} \n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment