Method Chaining in PHP

Program 1

<html>
<head><title>Demo</title></head>
<body>
    <center>
<?php 
        class A
        {
              function first()
              {
                  echo "This is a first method of class A<br>";
                  return $this;
              }
              function second()
              {
                  echo "This is a second method of class A<br>";
                  return $this;
              }
              function third()
              {
                  echo "This is a third method of class A<br>";
              }
        }

     $obj=new A();   
     $obj->first()->second()->third();
     
?>
</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 *