Field Manual PHP / Laravel reference
← PHP

Static

Static members belong to the class rather than an instance.

What it is

Static members belong to the class rather than an instance.

When to use it

Use for stateless helpers or named constructors; avoid global mutable state.

Syntax

public static function fromCents(int $cents): self {}

Example

final class Money
{
    private function __construct(public readonly int $cents) {}
    public static function fromCents(int $cents): self
    {
        return new self($cents);
    }
}
$money = Money::fromCents(1250);

Common mistakes

Static mutable state makes tests and long-lived workers unpredictable.

Related topics

Browse PHP