Skip to content

Persistent typed property must not be accessed before initialization #286

@janfejtek

Description

@janfejtek

Version: 3.1.2

Bug Description

When using non-nullable typed property marked as @persistent Error Typed property must not be accessed before initialization is thrown
This can be fixed by using nullable public ?int $id = null but I think that clearly marking variable as required for presenter is better for code readability.

Error occurs here:

$params[$name] = $this->$name;

Steps To Reproduce

class SomePresenter extends Presenter {
        /** @persistent */
        public int $id;
        
        public function actionSomething()
        {
        }
}

Possible Solution

Throw something like BadRequestException Missing parameter $id required by SomePresenter for typed properties
or
Do not throw error and skip all unitialized (or null) persistent values just by isset check

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions