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() { } } Quote Link to comment 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(){ } } ?> Quote Link to comment 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.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.