NYCPHP Meetup

NYPHP.org

[nycphp-talk] Multi-Inheritance in PHP 5

Adam Maccabee Trachtenberg adam at trachtenberg.com
Fri Oct 8 14:30:18 EDT 2004


On Fri, 8 Oct 2004, Hans Zaunere wrote:

> So really, how do interfaces provide a means for MH?  As I understand
> it, PHP support isn't quite like Java, so the way they do it doesn't
> seem possible.  What am I missing here?

They don't in the C++ way that you seem to be expecting. You cannot
have a child class inherit methods from multiple parents.

Instead, interfaces allow you to create a way to require a class to
implement a series of methods. Since you know they class must
implement foo() and bar(), then you know you can invoke them, just as
if the class extended a parent that implemented foo() and bar().

Alternatively, you can use __call() to aggregate a second class inside
the child class. Inside of __call(), you can embed logic to determine
how the methods are dispatched.

-adam

-- 
adam at trachtenberg.com
author of o'reilly's "upgrading to php 5" and "php cookbook"
avoid the holiday rush, buy your copies today!



More information about the talk mailing list