Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: What is method chaining in PHP?
Answer: Method chaining is a technique where multiple methods can be called on the same object in a single line. It improves code readability and conciseness.

Example:

class Calculator { 
private $result; 
public function add($a, $b) { 
$this->result = $a + $b; 
return $this; 

public function multiply($a) { 
$this->result *= $a; 
return $this; 


$total = (new Calculator())->add(3, 5)->multiply(2)->getResult();
Is it helpful? Yes No

Most helpful rated by users:

©2026 WithoutBook