Virtual pages from image gallery with Kirby 4

With Kirby 3 I used this tutorial to create my image gallery. The update gives me the following error:

public function image(?string $filename = null)

Whoops \ Exception \ ErrorException (E_COMPILE_ERROR)

Declaration of FotoPage::image(?string $filename = null) must be compatible with Kirby\Cms\Page::image(?string $filename = null): ?Kirby\Cms\File

Please see here Virutal pages on Kirby 4 - #2 by jimbobrjames

This does not solve the problem unfortunately.

The signature for the image method has changed, so you need to add the return type ?Kirby\Cms\File, that’s what @jimbobrjames meant, only with another example…

Unfortunately I still don’t know what to change since I don’t have the knowledge :-(.

public function image(string $filename = null): Kirby\Cms\File|null
{
 // code
}

The information after the colon is the return type hint, it tells you what a function will return.

In this case, you will get either a Kirby\Cms\File object, or null.

In Kirby 4, we added a lot more type hints to methods, so some of this might still need a fix in the docs.

2 Likes

Thank you! Everything else worked fine after the upgrade! Maybe you could edit the tutorial pages too.