Site icon DataFlair

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>

 

Exit mobile version