Questions about php objects.
淡淡烟草味
淡淡烟草味 2017-05-31 10:34:18
0
1
528

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?

淡淡烟草味
淡淡烟草味

reply all(1)
我想大声告诉你

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);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template