Skip to content

Entity Virtual Properties as Property Hooks PHP 8.4 #18201

@markusramsak

Description

@markusramsak

Description

Since PHP 8.4 property hooks are possible which could optionally replace the setter and getter of the Entities.
In the __get() and __set() methods there is at the moment no checks for virtual properties (only if configured with prefix _get as method).
This could be optionally added, so both can be used. I think it should be possible backward compatible.

virtual property getter $formatted_title

protected function _getFormattedTitle(): string
    {
        return $this->booking_date->i18nFormat('short') . ', ' . Number::formatOutput($this->amount) . ' EUR';
    }

property hook

public string $formatted_title {
        get {
            return $this->booking_date->i18nFormat('short') . ', ' . Number::formatOutput($this->amount) . ' EUR';
        }
}

and setter $title

protected function _setTitle($value)
    {
        return str_replace(["'", '"', '[', ']', '/', '\\', '{', '}'], '', $value);
    }

property hook:

public string $title {
        set {
            $this->title = str_replace(["'", '"', '[', ']', '/', '\\', '{', '}'], '', $value);
        }
}

CakePHP Version

5.1.5

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions