PHP Trait续

来源:互联网 发布:软件测试工程师学习 编辑:程序博客网 时间:2024/06/05 06:39
//如果Trait 父类 和 子类中都同时包含一个方法,最后保留的是Trait
中的方法
    class Person {
        public function hello() {
            echo "hello person<br/>";
        }
        public function driving() {
            echo "driving from person<br/>";
        }
    }
    class Student extends Person {
        use Drive;
        public function hello() {
            echo "hello student<br/>";
        }
    }
    trait Drive {
        public function hello() {
            echo "hello drive<br/>";
        }
        public function driving() {
            echo "driving from drive<br/>";
        }
    }
    $student = new Student();
    $student->hello();
    $student->driving();
原创粉丝点击