-1

i have a simple question in OOP

I've see in a lot of frameworks like Laravel something like this :

$data = Model::OrderBy('id','desc')->skip(5)->take(10)->get()->toArray();

My Question is, how can i can call a function after another function ?

Exemple :

class test{

public function test1(){}
public function test2(){}

}

how i can call the function test 2 after test 1 like that test1()->test2()

i hope the question is clear

tereško
  • 57,247
  • 24
  • 95
  • 149
REVERSI
  • 49
  • 5

1 Answers1

-1

In its simplest form you just have to return the current instance in all your chainable methods:

return this;

Often these chained methods return a new object instead of altering the current one though - this is called immutability or immutable objects.

Fitzi
  • 1,501
  • 13
  • 16