note 79673 deleted from language.oop5.basic by bjori
| From: | bjori@php.net | Date: | Sat, 24 May 2008 14:25:54 +0000 |
| Subject: | note 79673 deleted from language.oop5.basic by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-139699@lists.php.net to get a copy of this message | ||
Note Submitter: alexandre at dontspamme dot gaigalas dot net
----
In theory, it is possible to workaround and do multiple inheritance in PHP5 using magic methods. An
example:
<?php
class foo
{
function fooMethod($a)
{
echo 'fooMethod called with argument: '.$a.'<br>';
}
}
class bar
{
function barMethod($b)
{
echo 'barMethod called with arguments: '.$b.'<br>';
}
}
class multiple
{
private $_parents = array();
function __construct()
{
$this->_parents[] = new foo;
$this->_parents[] = new bar;
}
function __call($m,$a)
{
foreach ($this->_parents as $extended)
{
if (method_exists($extended, $m)) {
return call_user_func_array(array($extended,$m),$a);
}
}
}
}
$test = new multiple;
$test->fooMethod('test');
$test->barMethod('me');
?>
This, ovbiously needs some modifications to work with static methods (using Reflection API) and
obviously don't work with private methods.