haaglin Posted October 7, 2007 Share Posted October 7, 2007 Hi. Is it possible to have 1 class to extent 2 separate classes? I have 2 classes that are different, but they share a lot of the same functions.. In this example, i want class one and two to have the functions from class three, but i do not want class one to have the functions of class two.. class one { function one() { } } class two { function two() { } } class tree { function tree() { } } Link to comment https://forums.phpfreaks.com/topic/72222-solved-class-extending/ Share on other sites More sharing options...
GingerRobot Posted October 7, 2007 Share Posted October 7, 2007 Any number of classes can inherit from a single parent class. If class A is your parent, then class B,C,D etc can all be children of that class, without inheriting from each other. However, php does not support multiple inheritance, which is where a class extends multiple classes - that is, it has more than 1 parent. For example, class C cannot inherit from class A and B. You question wasn't entirely clear, however i think you wanted something like: <?php class three{ function three(){ } } class one extends three{ function one(){ } } class two extends three{ function two(){ } } ?> Link to comment https://forums.phpfreaks.com/topic/72222-solved-class-extending/#findComment-364158 Share on other sites More sharing options...
haaglin Posted October 7, 2007 Author Share Posted October 7, 2007 Thank you! Your example did exactly what i wanted to do.. Link to comment https://forums.phpfreaks.com/topic/72222-solved-class-extending/#findComment-364160 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.