PHP: One interface feature you should know

#[Pragmatic(Kiwi)]
2 min readFeb 28, 2023

Interfaces, in programming, allow us to create code that specifies which methods a class should implement without actually implementing it.

Interfaces are defined just like classes, but with the interface keyword:

<?php 

namespace App\Interfaces;

interface UserInterface
{
public function getUser(int $id): User;
}

As you can see, we can specify the method name, the parameters, the type of parameters, and the return type.

--

--