pixel
December 4, 2023, 11:39am
1
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
pixel
December 4, 2023, 12:23pm
3
This does not solve the problem unfortunately.
texnixe
December 4, 2023, 12:30pm
4
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…
pixel
December 4, 2023, 12:36pm
5
Unfortunately I still don’t know what to change since I don’t have the knowledge :-(.
texnixe
December 4, 2023, 12:40pm
6
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
pixel
December 4, 2023, 12:53pm
7
Thank you! Everything else worked fine after the upgrade! Maybe you could edit the tutorial pages too.