Last active
August 29, 2015 14:19
-
-
Save loranger/cc1212c7df43f615ecee to your computer and use it in GitHub Desktop.
overload inheritance
This file contains hidden or 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 | |
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