1

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'));
    }
2

1 Answer 1

0

The cakephp-ide-helper / bake issue is solved. Try updating with composer update and bake your annotations again.

Then your Table-classes should have updated annotations and the PhpStorm error should be gone because of the updated annotations.

Not the answer you're looking for? Browse other questions tagged or ask your own question.