Jump to content

What does this syntax mean in PHP?? Do you know ?


aabid

Recommended Posts

I just came up with a line of code that I am not able to understand what's it doing.

The code is:

function cost()
{
return $this->costStrategy->cost($this);
}

 

here costStrategy is a class property which holds a reference to the object of type CostStrategy class and cost() is a method defined in CostStrategy.

cost($this) is calling the cost method of the $this->costStrategy object (an instance of the CostStrategy class), and passing along the current object ($this, see docs)) as the first and only argument to that method.

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.