Jump to content

[SOLVED] Class extending


haaglin

Recommended Posts

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

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(){

}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.