1

I am wondering in Some of PHP frameworks uses methods like Class::function()->function($parm)->function($parm); for an example in Laravel DB::table('users')->where('name', 'John')->value('email');

How these methods are internally working?

How can I build such Kind of method of my own?

Please help me out.

0

1 Answer 1

1

Foo::function()->function Two() its a static call to a public function which returning a new instance.

Class foo{
      Public static function (){
            Return new class bar();
       }

Class bar{
     Public function functionTwo(){
         //Some code
     }

Keep in mind that this it is not always good because is violoting the Law of demeter https://en.m.wikipedia.org/wiki/Law_of_Demeter

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.