note 79673 added to language.oop5.basic

From: Date: Fri, 07 Dec 2007 16:44:18 +0000
Subject: note 79673 added to language.oop5.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-132928@lists.php.net to get a copy of this message
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. ---- Server IP: 200.185.126.110 Probable Submitter: 200.99.133.67 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php Edit -- https://master.php.net/note/edit/79673 Del: integrated -- https://master.php.net/note/delete/79673/integrated Del: useless -- https://master.php.net/note/delete/79673/useless Del: bad code -- https://master.php.net/note/delete/79673/bad+code Del: spam -- https://master.php.net/note/delete/79673/spam Del: non-english -- https://master.php.net/note/delete/79673/non-english Del: in docs -- https://master.php.net/note/delete/79673/in+docs Del: other reasons-- https://master.php.net/note/delete/79673 Reject -- https://master.php.net/note/reject/79673 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132928) next »