Pages object != Children object?

This is a Kirby 2 question, that I don’t know if it applies to K3.

While solving some issues on a K2 install I encountered something quite puzzling.

When trying to add a collection made through something like $pages->children() with a collection made through $collection = new Pages() then ->add(…) and running the result through a loop I was getting some k2 whoopsies.

I tried to var_dump both collections, and one came up as object Children and the other as object Pages. Creating the second collection also via new Pages() then ->add() solved my problems, but left me wondering if there is actually a difference I should observe when creating and adding collections of pages both in k2 and k3.

Thank you

Could you please post the code that caused the error?

Sure,

This template worked well:

edition-item.php

...
<?php $allItems = new Pages() ?>
<?php $allItems->add($p->find('exhibitions')->children()->visible()) ?>
<?php $allItems->add($p->find('events')->children()->visible()) ?>
<?php $allItems->add($p->find('associates-program')->find('research-modules')->children()->visible()) ?>
<?php if($p->find('writer-in-residency')->isVisible()): ?>
	<?php $allItems->add($p->find('writer-in-residency')) ?>
<?php endif ?>
<?php snippet('floating-shapes', ['c' => $allItems]) ?>

But this one did not:

events.php

...
<?php $allChildren = $p->children()->visible() ?>
<?php snippet('floating-shapes', ['c' => $allChildren ]) ?>

This is the snippet called in both templates.

floating-shapes.php

...
<?php $c = $c->sortBy('opening_date', 'asc') ?>
<?php	
$past =  $c->filter(function($p) {
	$now = new DateTime();
	return new DateTime($p->opening_date()) < $now;
})?>
<?php $past = $past->sortBy('opening_date','desc') ?>

<?php $c = $c->without($past)->add($past) /* <--- this caused an error... */ ?> 

<?php foreach($c as $w): ?>
	<?php if($w->uid() == 'writer-in-residency'): /* <--- ...at this line */?> 
    ...

… The whoops was: Call to undefined method Kirby::uid() on the last line.

Either removing the line where $past is added to $c, or changing events.php to this code, fixed the issue:

events.php (fixed)

<?php $allChildren = new Pages() ?>
<?php $allChildren->add($p->children()->visible()) ?>
<?php snippet('floating-shapes', ['c' => $allChildren ]) ?>

As mentioned, var_dumping the collection at events.php gave a different object depending on how it was created, if I use new Pages() I get object(Pages), if I use $var = $p->children()->visible I get object(Children)

Thanks