Skip to content

Instantly share code, notes, and snippets.

@spelcaster
Created May 23, 2017 21:17
Show Gist options
  • Save spelcaster/e331f49d677626dd9ef410a985432d92 to your computer and use it in GitHub Desktop.
Save spelcaster/e331f49d677626dd9ef410a985432d92 to your computer and use it in GitHub Desktop.
<?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