Best way to check for object type in collection

Hi,
I’m merging files and pages in a single collection and need to determine the object type of each individual entry. I’m using the following code

$files = new Collection($page->files());
$pages = new Collection($page->children()->listed());
$merged = $files->add($pages);

foreach ($merged as $entry) {
	if (is_a($entry, 'Kirby\Cms\Page')) {
		// I'm a page
	}
	if (is_a($entry, 'Kirby\Cms\File')) {
		// I'm a file
	}
}

Is this the best way to do it? Or is there a more elegant solution?

Thanks
Claus

What is the context? What is the use case? I’m not sure why you would want to do this. There might be a better solution if we knew the wider context.

The code is ok, but like @jimbobrjames already wrote: What is the purpose?

I’m building a website with a small photo blog/diary. Most uploads will be photos, but sometimes short text entries. Photos don’t need a title, sometimes a caption though. Photo and text entries should be displayed mixed, sorted by date.
So I’ve created a subpage called “diary”. All photos are being uploaded directly as attachments into that folder, for text entries I create subpages. Photo captions are being added via the files blueprint.

Ah, alright, the stuff is sorted… that wasn’t obvious from your code above. Makes sense now. And checking for the object types makes sense as well, because you want a different mark up for files and text.