Page model throws an error in Kirby 4

I am currently updating a website with Kirby 3.9.6 to Kirby 4. So far I have used a page model to generate virtual user pages.

<?php
 
class MembersPage extends Page {
  public function children() {
    $pages = [];
    $users = kirby()->users();
    foreach ($users as $key => $user) {
      $pages[] = [
        'slug' => Str::slug($user->id()), // or username if unique
        'num' => $user->indexOf($users),
        'template' => 'member',
        'model' => 'member',
        'content' => [
          'title' => $user->username(),
          'email' => $user->email(),
          'memberAcadDegree' => $user->memberAcadDegree(),
          'memberFirstName' => $user->memberFirstName(),
          'memberLastName' => $user->memberLastName(),
          ...

This model now gives this error under Kirby 4:

Whoops \ Exception \ ErrorException (E_COMPILE_ERROR)
Declaration of MembersPage::children() must be compatible with Kirby\Cms\Page::children(): Kirby\Cms\Pages

I´m completely lost. Checked Guide, Reference and Forum. Any advice, how to fix this?

Yes, you need to make sure that the methods you overwrite in your model use the same signature regarding parameters, parameter types and return types. In case of the children() method, you need to add the return type (Pages), see examples of Virtual pages in our docs:

1 Like

Thank you very much, Sonja. The example in your link looks like I can understand it too :wink:

Addendum: Works perfectly!

consider adding the code to retrieve and set the $this->children within the children() method in the model for a huge performance boost on repeated calls.