php class knowledge --- trait characteristics

# Since php class supports only single inheritance, but we need to use some of the outstanding characteristics of the class, and therefore have a trait 

<? Php trait under cpc #trait method can only use public { function trainning_hoaring () { echo " wailing child Hey ~ wailing children fed ~ " ; } } trait CJ { function trainning_hoaring () { echo " eh Hey ~ ~ ~ " ; } } class Me { use CPC, CJ {#use means that the structure of the above-defined trait cj :: trainning_hoaring INSTEAD cpc; # due cpc and cj is defined in the same manner, so if one of them is selected, it is necessary to use an expression
# trait insteadof using unused trait cj :: trainning_hoaring
AS cjhoaring; # CJ to trait
trainning_hoaring from a characteristic alias cjhoaring
        :: trainning_hoaring cpc AS cpchoaring; # ditto role 
   }
}
$ cpc
= new new Me (); $ cpc -> trainning_hoaring ();
>?

Output:

Hey eh ~ ~ ~

Guess you like

Origin www.cnblogs.com/saintdingspage/p/10964074.html