Field Manual PHP / Laravel reference
← PHP

Interfaces

An interface defines a contract that implementations must satisfy.

What it is

An interface defines a contract that implementations must satisfy.

When to use it

Use at a real boundary with interchangeable implementations, such as a payment provider.

Syntax

interface PaymentGateway
{
    public function charge(int $amount): bool;
}

Example

class FakeGateway implements PaymentGateway
{
    public function charge(int $amount): bool
    {
        return $amount > 0;
    }
}

Common mistakes

A bool often cannot express pending or unknown payment outcomes; use richer results in real integrations.

Related topics

08. Design API / interfaces