Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Propriétés dans les interfaces

<?php

interface i { 
    public $p { get;}
}

class x implements i {
    public $p = 1 { get => $this->p;}
}

echo (new x)->p;

Depuis PHP 8.4, il est possible d’avoir des propriétés dans une interface.

En fait, il faut ajouter un hook à une propriété. Comme il s’agit d’une interface, ce hook ne peut pas avoir de corps.

Ainsi, le hook doit être défini dans chaque classe qui implémente l’interface.

See Also

PHP Features

Last updated: 22 October 2026