On Wed, 2002-04-10 at 22:58, Andi Gutmans wrote:
> I still prefer to keep PHP a relatively easy to learn, simple yet powerful
> language.
> I think this is a huge overkill and prefer going with something like I
> proposed.
> Anyway the inheritance debates have been going on for years and I doubt
> we'll solve all possible scenarios for the first time in programming
> language history. Also historically the languages which do try and solve
> lots of scenarios end up having extremely complex mechanisms to do so.
> I'll sum up my proposal again.
> Support the following:
> class MyClass extends MyParent aggregates Timer, FooBar
> {
> }
>
> $obj = new MyClass; // Creates $obj->Timer and $obj->FooBar
> $obj->method(); // Searches MyClass, MyParent if not found tries to call
> the method on $obj->Timer followed by $obj->FooBar
In my head there was always a method_name => object hash in the
aggregating object, but then you can't deal with an aggregated object
aggregating another object. Search every time it must be.
> If you want to access an aggregated object directly you can do:
> $obj->Timer->method();
Actually, even if class != type in PHP, I think Wez's suggestion is a
better way of expressing this:
($obj as Timer)->method();
However, your $obj->Timer->method() can be implemented with overloading,
so it would make the implementation less complex.
There's one important thing missing in your suggestion though: the
runtime aggregate() function. We also need aggregate_info($this) for
listing aggregated classes, deaggregate($this, "class") and
serialization support (you mentioned that didn't you?)
Some issues I thought of that need to be resolved:
* Which methods should be skipped? IMHO it makes sense to skip
ZE1-style constructors and methods starting with at least one
underscore. Those starting with two underscores are reserved, while it
is common practice to use one underscore for "declaring" a method as
private.
* Should it be possible to have multi-level aggregation?
class a aggregates b {}
class b aggregates c {}
class c { function foo() {} }
$a = new a;
$a->foo();
IMHO, the only sensible thing would be for this to call c::foo(), or
else objects would get different interfaces in different contexts.
* Dealing with possible loops:
class a aggregates b {}
class b aggregates a {}
$a = new a;
$a->unknown_method();
Should it be illegal to "loop-aggregate" classes, or should it be
detected at runtime? I'm not sure.
- Stig
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php