note 88121 added to function.aggregate
| From: | the-user at gradespro dot com | Date: | Sun, 11 Jan 2009 21:44:00 +0000 |
| Subject: | note 88121 added to function.aggregate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149073@lists.php.net to get a copy of this message | ||
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. ;)
----
Server IP: 212.124.37.9
Probable Submitter: 91.52.216.112
----
Manual Page -- http://www.php.net/manual/en/function.aggregate.php
Edit -- https://master.php.net/note/edit/88121
Del: integrated -- https://master.php.net/note/delete/88121/integrated
Del: useless -- https://master.php.net/note/delete/88121/useless
Del: bad code -- https://master.php.net/note/delete/88121/bad+code
Del: spam -- https://master.php.net/note/delete/88121/spam
Del: non-english -- https://master.php.net/note/delete/88121/non-english
Del: in docs -- https://master.php.net/note/delete/88121/in+docs
Del: other reasons-- https://master.php.net/note/delete/88121
Reject -- https://master.php.net/note/reject/88121
Search -- https://master.php.net/manage/user-notes.php