zoukankan      html  css  js  c++  java
  • php

    自 PHP 5.4.0 起,PHP 实现了一种代码复用的方法,称为 trait。

    Trait 是为类似 PHP 的单继承语言而准备的一种代码复用机制。Trait 为了减少单继承语言的限制,使开发人员能够自由地在不同层次结构内独立的类中复用 method。Trait 和 Class 组合的语义定义了一种减少复杂性的方式,避免传统多继承和 Mixin 类相关典型问题。

    Trait 和 Class 相似,但仅仅旨在用细粒度和一致的方式来组合功能。 无法通过 trait 自身来实例化。它为传统继承增加了水平特性的组合;也就是说,应用的几个 Class 之间不需要继承。

    <?php
    trait ezcReflectionReturnInfo {
        function getReturnType() { /*1*/ }
        function getReturnDescription() { /*2*/ }
    }
    
    class ezcReflectionMethod extends ReflectionMethod {
        use ezcReflectionReturnInfo;
        /* ... */
    }
    
    class ezcReflectionFunction extends ReflectionFunction {
        use ezcReflectionReturnInfo;
        /* ... */
    }
    ?>
    

     具体参考:http://php.net/manual/zh/language.oop5.traits.php

     

  • 相关阅读:
    国产html编辑器
    豆瓣90mhz电台还行
    购物搜索
    linode vps 优化集锦
    这个系统,我看行,
    代理网站
    合理设置域名TTL值给网站加速
    dns切换到dnspod
    elixir usage
    JSSH介绍
  • 原文地址:https://www.cnblogs.com/leilei-1/p/9614035.html
Copyright © 2011-2022 走看看