Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why would there be more than one object operator in a line of code in php?

I'm a n00b tying to get my head around the operator syntax. I understand it's called the object operator and I can see how it's used (Where do we use the object operator "->" in PHP?) by itself.

I'm trying to learn what the purpose is when they are strung together like in this snippet (e.g. "switch($this->request->param('id')):

here's a snippet of code from a site using Kohana:

public function action_list()
{
    $connections = ORM::factory('Connection')
        ->with('property')
        ->with('inviter');
    switch ($this->request->param('id')) {
    // more code...
        }
    }
like image 475
DBWeinstein Avatar asked Dec 29 '25 18:12

DBWeinstein


1 Answers

It's called "method chaining". It allows you to apply more then one method, and thus do more then one thing, in one call. It's sort of the OOP equivalent of nesting functions.

like image 88
John Conde Avatar answered Jan 01 '26 06:01

John Conde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!