http://forum.php.su/topic.php?fo...2&topic=1661
- вопрос об осуществлении множественного наследования в PHP.
Представляю вашему вниманию класс Inheritance, который позволяет наследовать от произвольных классов без их модификации, а так же сохраняющий области видимости при вызове методов.
PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- class Exception_Callback_Absent extends Exception
- {
- function __construct()
- {
- parent::__construct();
- }
- }
- class Exception_Callback_Deny extends Exception
- {
- function __construct()
- {
- parent::__construct();
- }
- }
- class Inheritance
- {
- protected function createInheritance($rParent, $bAllowInstances=false)
- {
- $bReject=false;
- {
- foreach($this->_rgInheritance as $rClass)
- {
- {
- $bReject=true;
- break;
- }
- }
- }
- else
- {
- $bReject=true;
- }
- if($bAllowInstances || !$bReject)
- {
- $this->_rgInheritance[]=$rParent;
- }
- }
- public function __call($sMethod, $rgParameters)
- {
- $fnBind = function($sMethod, $rgParameters)
- {
- {
- $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();
- }
- }
- }