DylanBaine.com / Browse / Properties in PHP interfaces.

Properties in PHP interfaces.

Do PHP interfaces have properties?

Unfortunately, no. There is no current versions of PHP interfaces support properties.

Can I put properties in PHP interfaces?

You can’t declare properties in PHP interfaces, but you can add a doc-block to interfaces that infer properties. See below for an example to implement properties in PHP interfaces.

How to add properties to PHP interfaces.

Since there is not official support for properties in PHP interfaces, you can use doc-blocks to softly define properties on an interface.

<?php

/**
* @property string $username
* @property string $password
*/
interface User {
    function login(): void;
}