Last active
December 21, 2015 00:09
-
-
Save beeblesox/6218135 to your computer and use it in GitHub Desktop.
This is a way you could achieve multiple, variable inheritance. I'm interested in what kind of performance hit this might have.
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 | |
class Base { | |
function bse(){ echo "base <br />"; } | |
} | |
/* You would have to make a dependency-based loader | |
* to keep track of class names. Here, I'm just hard | |
* coding to show that it could work... | |
*/ | |
$parent_class = 'Base'; | |
eval("class _BaseA extends $parent_class {}"); | |
class BaseA extends _BaseA { | |
function a(){ echo "a <br />"; } | |
} | |
$parent_class = 'BaseA'; | |
eval("class _BaseB extends $parent_class {}"); | |
class BaseB extends _BaseB { | |
function b(){ echo "b <br />"; } | |
} | |
$parent_class = 'BaseB'; | |
eval("class _End extends $parent_class {}"); | |
class End extends _End { | |
function nd(){ echo "end <br />"; } | |
} | |
$ab = new End(); | |
$ab->bse(); // base | |
$ab->a(); // a | |
$ab->b(); // b | |
$ab->nd(); // end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment