$page object performance questions

1. How many times does it go through the content?

Does it cache the query the first time, or does it go through the files every time?

$children1 = $page->children();
$children2 = $page->children();
$children3 = $page->children();

2. Same as the first question

$children1 = page()->children();
$children2 = page()->children();
$children3 = page()->children();

3. Why using $page instead of page()?

4. If I ask the same about $site / site(), do I get the same answers?

1 Like

Yes, it does.

The result of page() is cached as well.

Regarding performance: Less methods need to be called if you use $page, as that variable is already defined. page() is more for use in functions with different variable scopes.
In the end it shouldn’t matter which one you use, but $page also worked in Kirby 1 and is used in examples and themes a lot.

Yes.

Awesome! I use page() when $page is not defined, for example in plugin functions, called from the template.

Sidenote
My first bet who would answer this question was you @lukasbestle. How correct I was! My second bet would be @texnixe.

Me too. :smile:
That’s exactly why page() exists in Kirby 2.

Haha. :smiley:
Yes, we moderators basically live in this forum. :stuck_out_tongue:

There is some truth in that :laughing:

@lukasbestle @texnixe I love you both so much for living here :slight_smile: