On 10/04/02, "Zeev Suraski" <[EMAIL PROTECTED]> wrote:
> Hmm, you refer to interfaces a-la COM?  Hmm, I was under the impression 
> that if we use interfaces, it'll be the same as Java, and then what you 
> said about naming conflicts doesn't apply at all.  QueryInterface() is a 
> hack, which may have a positive side effect (avoids naming collisions), but 
> it's still a hack :)

I don't see how we can avoid those conflicts, no matter what style of
interface we go for, unless we have some kind of interface casting
mechanism.  So, thats QueryInterface for COM-style interfaces, some kind
of "as" operator for Java style interfaces, or some kind of dynamic cast
operator if we leave out interfaces and go for MI.

So, what next?  It seems to be generally accepted (here on php-dev) that
interfaces in the context of PHP are the same thing as MI.
I can see (thanks to Brad digging around the ZE recently) that MI can
be implemented relatively quickly and easily.

To satisfy the need for aggregating at runtime, I'd suggest a delegate
keyword which would work by forwarding calls from the outer object to
an inner instance, kept in a variable:
class D extends A {
   delegate A to $ainstance;
}
The call handler for instances of D would forward calls for methods in
the class A to $ainstance.  At the simplest level, the ZE could actually
compile the class entry for D so that there are implicit function declarations
like this:
function Foo() {
  $args = func_get_args();
  return call_user_func_array(array($this->ainstance, "Foo"), $args);
}

If we have MI, we will need some kind of "as" or dynamic cast operator
to resolve naming ambiguities - the as operator might work something like
this:

Syntax: $object as <ClassName>
1. Locate class entry for <ClassName>, complain if not found.
2. Verify that $object is an instance of <ClassName> (or has a delegate)
3. If the $object has a delegate for <ClassName>, return that delegate
4. Create $proxy object, which holds the class entry for the desired class
   and a reference to $object; return $proxy.

The call handler (or ZE2 equivalent) in $proxy will verify that a called
method exists in the class entry and then forward the call to the appropriate
method in $object.

In summary: MI, "as" operator and "delegate" keyword.

Am I making sense - is this feasible?
Does this cover all the bases?
What doesn't it cover?

--Wez.


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to