On 10/04/02, "Andi Gutmans" <[EMAIL PROTECTED]> wrote:
> 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
>
> If you want to access an aggregated object directly you can do:
> $obj->Timer->method();
>
> Got to go to bed now ;)
I think we need just one more extra on top of this: some kind of
"as" operator. Here's why:
class Timer {
function Tick() { echo "Timer Tick"; }
}
class FooBar {
function Tick() { echo "FooBar Tick"; }
}
class MyClass extends MyParent aggregates Timer, FooBar
{
}
$a = new FooBar();
$b = new MyClass();
function ExpectsFooBar($foo)
{
$foo->Tick();
}
ExpectsFooBar($a); // outputs "FooBar Tick"
ExpectsFooBar($b); // outputs "Timer Tick" - incorrect
ExpectsFooBar($b->FooBar); // outputs "FooBar Tick"
So, should all code try looking for a member named after
the class whose method they want to call? It won't always
work, and doesn't really convey what is going on.
ExpectsFooBar($b as FooBar);
This explicitly says what is going on. It's operation
is simple: if $b is_a FooBar return $b, else if $b has_a FooBar,
return $b->FooBar.
--Wez.
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php