note 123648 added to language.oop5.traits

From: Date: Sat, 02 Mar 2019 16:03:42 +0000
Subject: note 123648 added to language.oop5.traits
Groups: php.notes 
Request: Send a blank email to php-notes+get-210294@lists.php.net to get a copy of this message
Here is an example how to work with visiblity and conflicts. <?php trait A { private function smallTalk() { echo 'a'; } private function bigTalk() { echo 'A'; } } trait B { private function smallTalk() { echo 'b'; } private function bigTalk() { echo 'B'; } } trait C { public function smallTalk() { echo 'c'; } public function bigTalk() { echo 'C'; } } class Talker { use A, B, C { //visibility for methods that will be involved in conflict resolution B::smallTalk as public; A::bigTalk as public; //conflict resolution B::smallTalk insteadof A, C; A::bigTalk insteadof B, C; //aliases with visibility change B::bigTalk as public Btalk; A::smallTalk as public asmalltalk; //aliases only, methods already defined as public C::bigTalk as Ctalk; C::smallTalk as cmallstalk; } } (new Talker)->bigTalk();//A (new Talker)->Btalk();//B (new Talker)->Ctalk();//C (new Talker)->asmalltalk();//a (new Talker)->smallTalk();//b (new Talker)->cmallstalk();//c ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.142 (proxied: 46.214.9.38) ---- Manual Page -- http://php.net/manual/en/language.oop5.traits.php Edit -- https://master.php.net/note/edit/123648 Del: integrated -- https://master.php.net/note/delete/123648/integrated Del: useless -- https://master.php.net/note/delete/123648/useless Del: bad code -- https://master.php.net/note/delete/123648/bad+code Del: spam -- https://master.php.net/note/delete/123648/spam Del: non-english -- https://master.php.net/note/delete/123648/non-english Del: in docs -- https://master.php.net/note/delete/123648/in+docs Del: other reasons-- https://master.php.net/note/delete/123648 Reject -- https://master.php.net/note/reject/123648 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#210294) next »