Click to See Complete Forum and Search --> : Interfaces and Inheritence


kkobashi
09-04-2004, 11:05 PM
Under PHP5:

Can a class implement more than one interface:

class SomeClass implements Interface1, Interface2
{
}

Can a class implement AND extend another class?

class SomeClass extends AnotherClass implements Interface1
{
}

From my understanding, PHP5 does not allow multiple inheritance. Thus use of one of the techniques above is needed.

goldbug
09-05-2004, 01:21 AM
Originally posted by kkobashi
Under PHP5:

Can a class implement more than one interface:

class SomeClass implements Interface1, Interface2
{
}

IIRC, I read somewhere that this was possible.... easiest way to find out is to try.


Can a class implement AND extend another class?

class SomeClass extends AnotherClass implements Interface1
{
}

From my understanding, PHP5 does not allow multiple inheritance. Thus use of one of the techniques above is needed. See previous note :)

Shrike
09-09-2004, 10:58 AM
PHP5 supports single inheritance and multiple implementations, at the same time.

class bar extends foo implements moo, doo, boo {

}

Not sure what that has to do with multiple inheritance though?

BSTRhino
09-11-2004, 10:10 AM
kkobashi, you are right, PHP doesn't support multiple inheritance. I think you're confusing inheritance and interfaces. Interfaces are used to get around the multiple inheritance problem, which sometimes limits you from giving certain objects the functionality they need.

Interfaces are used heaps in Java. But to be honest, I can't think of a useful purpose for them in PHP.

Weedpacket
09-12-2004, 02:43 AM
Originally posted by BSTRhino
Interfaces are used heaps in Java. But to be honest, I can't think of a useful purpose for them in PHP. You can if($object instanceof InterfaceName)

http://www.phpbuilder.com/board/showthread.php?s=&threadid=10284617