开发者

multiple class inheritance

开发者 https://www.devze.com 2022-12-26 08:44 出处:网络
In PHP, is it possible to have multiple inheritance (by the nature of the PHP, not writting modification code)?

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

精彩评论

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