Loading, please wait...

A to Z Full Forms and Acronyms

How to implement a cascaded function call in PHP | PHP programs

Jan 20, 2022 PHP, 1097 Views
How to implement a cascaded function call in PHP | PHP programs

How to implement a cascaded function call in PHP | PHP programs

We will implement a cascaded function call using $this, it means we can call multiple functions in a single code statement.

<?php

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();
?>
A to Z Full Forms and Acronyms