Skip to content

Property hooks from PHP 8.4 #684

Open
@hrach

Description

@hrach

As PHP 8.4 comes with property hooks we could remove virtual properties, as they would be completely modelled
by a custom property with getter hook.

This:

/** ...
 * @property-read int                $age             {virtual}
 */
final class Author extends Entity
{
	protected function getterAge(): int
	{
		if ($this->born === null) {
			return 0;
		}

		return ((int) date('Y')) - ((int) $this->born->format('Y'));
	}
}

Would become

/** ...
 */
final class Author extends Entity
{
	public int $age {
		get {
			if ($this->born === null) {
				return 0;
			}

			return ((int) date('Y')) - ((int) $this->born->format('Y'));
		}
	}
}

Please note, that this would not mean removing custom getters/setters support, as they're still needed for non-virtual properties.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions