class A1{ база }
class B1 extends A1{}
class B2 extends A1{}
и вот тут появился класс
class A2{другая база}
теперь надо чтоб
class B1 extends A1 и A2{}
это возможно как нибудь?
class Exception_Callback_Absent extends Exception
{
function __construct()
{
parent::__construct();
}
}
class Exception_Callback_Deny extends Exception
{
function __construct()
{
parent::__construct();
}
}
class Inheritance
{
protected $_rgInheritance=array();
protected function createInheritance($rParent, $bAllowInstances=false)
{
$bReject=false;
if(get_class($this)!=get_class($rParent))
{
foreach($this->_rgInheritance as $rClass)
{
if(get_class($rClass)==get_class($rParent))
{
$bReject=true;
break;
}
}
}
else
{
$bReject=true;
}
if($bAllowInstances || !$bReject)
{
$this->_rgInheritance[]=$rParent;
}
}
public function __call($sMethod, $rgParameters)
{
$fnBind = function($sMethod, $rgParameters)
{
if(method_exists($this, $sMethod))
{
$rReflect = new ReflectionMethod($this, $sMethod);
if($rReflect->isPrivate())
{
throw new Exception_Callback_Deny();
}
return $this->$sMethod($rgParams);
}
else
{
throw new Exception_Callback_Absent();
}
};
$bExecuted=false;
foreach($this->_rgInheritance as $rParent)
{
try
{
$fnBind = $fnBind->bindTo($rParent, $rParent);
$fnBind($sMethod, $rgParameters);
$bExecuted=true;
break;
}
catch(Exception_Callback_Deny $e)
{
throw $e;
}
catch(Exception_Callback_Absent $e)
{
continue;
}
}
if(!$bExecuted)
{
throw new Exception_Callback_Absent();
}
}
}
class Foo
{
public function doFoo()
{
echo('called doFoo()'.PHP_EOL);
}
protected function protectedFoo()
{
echo('called protectedFoo()'.PHP_EOL);
}
}
class Bar
{
public function doBar()
{
echo('called doBar()'.PHP_EOL);
}
private function privateBar()
{
echo('called privateBar()'.PHP_EOL);
}
}
class FooBar extends Inheritance
{
public function __construct()
{
$this->createInheritance(new Foo);
$this->createInheritance(new Bar);
}
}
$rTest = new FooBar();
$rTest->doFoo();
$rTest->doBar();
$rTest->protectedFoo();
$rTest->privateBar();
$rTest->notExists();