开发者

multiple class inheritance

In PHP, is it possible to have multiple inheritance (by the nature of the PHP, not writting modification code)?

For example :

class a
{
    public fun开发者_StackOverflowction foo();
}

class b
{
    public function bar();
}

class c extends a, b
{
    public function baz();
}


No. There's no real multiple inheritance in PHP and thats a good thing. See the other answers for alternatives.

Edit: By now, PHP supports Traits, of which one class can include more than one. They avoid the usual problems of multiple inheritance by throwing an error or requiring you to alias conflicting names.


class A extends B{

}

class B extends C{

}

class C{

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜