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>

 

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *