When using the API of KIRBY (a CMS), I found the following writing method:
$page->children()->visible();
What does this way of writing mean? Is it a nested function within a function in an object?
我想大声告诉你2017-05-31 10:36:18
I haven’t seen its source code, but it’s like this, $page->children()
returns an object, and this object has the method visible()
. So you can call it like this, which is also called chain call.
Give me an example
class Wallet
{
protected $money;
public function money()
{
$this->money = new Money();
return $this->money;
}
}
class Money
{
protected $total;
public function used($count)
{
$this->total -= $count;
}
}
You can chain calls like this
$user = new User();
$user->money()->used(23);