Web Hosting Talk







View Full Version : extend more than one class PHP


TranceNote
04-08-2005, 04:45 AM
Hello!

Im having a small problem with classes in PHP, I want to extend more then one class but I dunno if I can?

for example can I do like this:

class monkey extends animal, cage {

}

if it is possible which one of them will be concidered "parent".

in java you would have to use "implements" for the second class but that recuires cage to be a interface.

What are the rules for php for this problem? =)

Thanks!

hiryuu
04-08-2005, 05:30 AM
In PHP4, I don't think you can do this (I can't say I've tried, though). PHP5, like Java, supports one parent and multiple interfaces.

TranceNote
04-08-2005, 05:51 AM
Originally posted by hiryuu
In PHP4, I don't think you can do this (I can't say I've tried, though). PHP5, like Java, supports one parent and multiple interfaces.

Ok thanks!

krumms
04-08-2005, 09:17 AM
In PHP4, I don't think you can do this (I can't say I've tried, though).


Try aggregation in PHP4. It's deprecated, evil, defiled and broken, but it's there if you really want it.

mfonda
04-08-2005, 02:57 PM
PHP does not support multiple inheritance, nor is it ever going to. (There has been a lot of discussion on this, see mailing list archives if you want more information)

However, classes can implement multiple interfaces.