Method Chaining in PHP
by TechVidvan Team
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>
Tags: method chainingmethod chaining in phpPHPphp method chainingphp practicalphp programphp program on method chaining
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.