Traits in PHP Part – 1

Program 1

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

     class First
     {
            use display,show;
            
     }
     class Second
     {
        use display,show{
                  
        }
     }
   $f=new First();
   $f->displaydata();
   $f->showdata();
   $s=new Second();
   $s->displaydata();
   $s->showdata();
?>
</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 *