note 88121 deleted from function.aggregate by danbrown

From: Date: Sun, 11 Jan 2009 21:47:27 +0000
Subject: note 88121 deleted from function.aggregate by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149074@lists.php.net to get a copy of this message
Note Submitter: the-user at gradespro dot com ---- The aggregate-Function could be a good replacement for multiple inheritance, but one feature of PHP is missing: interface foo_interface { public function foo(); } class MyFoo implements foo_interface { public function foo() { echo 'Bar'; } } interface random_interface { public function getRand(); } class MyRandom implements random_interface { public function getRand() { switch(rand() % 4) { case 0: return 4711; case 1: return 1337; case 2: return 0815; case 3: return 1; } } } // Multiple Inheritance! class MyClass implements foo_interface, random_interface { public function __construct() { aggregate($this, 'MyFoo'); aggregate($this, 'MyRandom'); } } This method is called Mixin in languages like D, but PHP won't accept, that MyClass implements the Interfaces. A mixin-Keyword would be really useful in PHP: class MyClass implements foo_interface, random_interface { mixin MyFoo; // implicit aggregation mixin MyRandom; } But these are only dreams like defaultimplementations for interfaces. ;)

« previous php.notes (#149074) next »