Skip to main content
changed title appropriately
Link
dbf
  • 3.5k
  • 1
  • 27
  • 34

$class->method()->two(). How to chain methods in PHP?

Source Link
carlos
  • 300
  • 3
  • 13

$class->method()->two(). How?

I have a question about how is the best way to realize it.

class name {
  public function method($a){ 
    $this->a = $a; 
  }
  public function two($b){
    $this->b = $b;
  }
}

How I call $class->method('a')->two('b'); ?

return __CLASS__; // self?

on every method? or what? idk what is the best way or how all frameworks realize it.

If anyone can guide me I'll be very greatful... thanks!