The source code to implement cascaded function call is given below. The given program is compiled and executed successfully.
<?php
//PHP program to implement cascaded function call
class Sample
{
public function fun1()
{
print ("Fun1() called<br>");
return $this;
}
public function fun2()
{
print ("Fun2() called<br>");
return $this;
}
public function fun3()
{
print ("Fun3() called<br>");
return $this;
}
}
$S = new Sample();
$S->fun1()
->fun2()
->fun3();
?>
Output:
Fun1() called
Fun2() called
Fun3() called
Explanation:
In the above program, we created a class Sample that contains three functions fun1(), fun2(), and fun3(). Here, all functions return the $this. That's why we are able to call multiple functions in a single statement.
Program/Source Code:
The source code to implement cascaded function call is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a class Sample that contains three functions fun1(), fun2(), and fun3(). Here, all functions return the $this. That's why we are able to call multiple functions in a single statement.
need an explanation for this answer? contact us directly to get an explanation for this answer