note 75010 added to language.oop5.magic

From: Date: Tue, 08 May 2007 14:43:59 +0000
Subject: note 75010 added to language.oop5.magic
Groups: php.notes 
Request: Send a blank email to php-notes+get-126327@lists.php.net to get a copy of this message
There is no need to use eval() to mimic mixins (i.e., multiple inheritance) within PHP 5. You only need to: <?php class MyClass { private $_obj = null; public function __construct($obj) { $this->_obj = $obj; } public function __call($method, $args) { if (!method_exists($this->_obj, $method)) { throw new Exception("unknown method [$method]"); } return call_user_func_array( array($this->_obj, $method), $args ); } } ?> You could just as easily add an addMixin() method that would allow you to add multiple objects to an array, and then iterate over that array until you found the right method. As noted, these are referred to as a Mixins in other languages. ---- Server IP: 69.147.83.197 Probable Submitter: 71.223.245.239 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.magic.php Edit -- https://master.php.net/note/edit/75010 Del: integrated -- https://master.php.net/note/delete/75010/integrated Del: useless -- https://master.php.net/note/delete/75010/useless Del: bad code -- https://master.php.net/note/delete/75010/bad+code Del: spam -- https://master.php.net/note/delete/75010/spam Del: non-english -- https://master.php.net/note/delete/75010/non-english Del: in docs -- https://master.php.net/note/delete/75010/in+docs Del: other reasons-- https://master.php.net/note/delete/75010 Reject -- https://master.php.net/note/reject/75010 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126327) next »