Site icon DataFlair

Traits in PHP Part – 2

Program 1

<html>
<head><title>Demo</title></head>
<body>
    <center>
<?php
     trait display
     {
          public function displaydata()
          {
             echo "<font color=green>Hello Friends How are you this is display data method of trait display.....</font><br>";
          }
     }
     trait show
     {
        public function displaydata()
        {
           echo "<font color=blue>Hello Friends How are you this is display data method of trait show.....</font><br>";
        }

     }
     class First
     {
         use display,show{
                display::displaydata insteadOf show;
                show::displaydata as newdisplay;
                
         }

         public function displaydata()
         {
            echo "<font color=red>Hello Friends How are you this is display data method of First class.....</font><br>";
         }

     }
     $f=new First();
     $f->displaydata();
     $f->newdisplay();
?>
</center>
</body>
</html>

 

Exit mobile version