Skip to content

Instantly share code, notes, and snippets.

@loranger
Last active August 29, 2015 14:19
Show Gist options
  • Save loranger/cc1212c7df43f615ecee to your computer and use it in GitHub Desktop.
Save loranger/cc1212c7df43f615ecee to your computer and use it in GitHub Desktop.
overload inheritance
<?php
error_reporting(E_ALL);
/**
* Father
*/
class Father
{
protected $extended_values = [];
function __construct()
{
$this->say("I'm your father");
}
public function &__get($name)
{
return $this->extended_values[$name];
}
public function __set($name, $value)
{
$this->say(sprintf(" Setting %s", $name));
$this->extended_values[$name] = $value;
}
public function say($value)
{
printf("{$value} \n");
}
public function __destruct()
{
var_dump($this->extended_values);
}
}
/**
* Kid
*/
class Kid extends Father
{
function __construct()
{
parent::__construct();
$this->say("Noooooooo");
}
public function init()
{
$vars = ['saber' => 'green', 'arm' => 'left'];
foreach ($vars as $key => $value) {
$this->dynamicVar[$key] = $value;
}
$this->dynamicVar['master'] = 'obi-wan';
}
}
$test = new Kid();
$test->init();
$test->sister = 'Leila';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment