Multiple inheritance in php

Finally after long long waiting there is better way we can perform multiple inheritance in PHP5.
hang on hang on. Its call “Traits”. Trait is similar to other classes, It is not possible to instantiate a Trait on its own. If you want to do some more study you can refer documentation.

class BaseClass {
    public function Hello() {
        echo 'Hello ';
trait OtherCls {
    public function Hello() {
        echo 'World!';
class MyHelloWorld extends BaseClass {
    use OtherCls;
$o = new MyHelloWorld();
Output: Hello world
Share this nice post:

4 thoughts on “Multiple inheritance in php

  1. I have been examinating out a few of your stories and it’s pretty clever stuff. I will definitely bookmark your blog.

  2. Pretty section of content. I just stumbled upon your weblog and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently quickly.

Comments are closed.