I recently created a new project in CakePHP 5 which is PHP 8.1+ compatible and accepts named parameters. I freshly baked a model and in the controller, when using PhpStorm (2023.1.2), I get a highlighted error.
Note that the code itself executes fine, it's PhpStorm that is calling it an error.
The tutorial/baked controller errors out in the editor with the following (Components
is a hasMany
relationship):
public function view(?string $id = null): void
{
$unit = $this->Units->get($id, contain: ['Components']);
$this->set(compact('unit'));
}
PhpStorm gives me:
Unknown named parameter 'contain'
Prior to CakePHP 5, the syntax was:
public function view(?string $id = null): void
{
$unit = $this->Units->get($id, ['contain' => ['Components']]);
$this->set(compact('unit'));
}