Jump to content

Operator question


reddog

Recommended Posts

Object Operator.

Method chaining is read left to right (left associative):

<?php

 

class Test_Method_Chain

{

    public function One()

    {

        echo "One" . PHP_EOL;

        return $this;

    }

 

    public function Two()

    {

        echo "Two" . PHP_EOL;

        return $this;

    }

 

    public function Three()

    {

        echo "Three" . PHP_EOL;

        return $this;

    }

}

 

$test = new Test_Method_Chain();

 

$test->One()->Two()->Three();

 

/* Ouputs:

One

Two

Three

*/

?>

Link to comment
https://forums.phpfreaks.com/topic/249295-operator-question/#findComment-1280100
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.