Field Manual PHP / Laravel reference
← PHP

Classes

Classes combine behavior with state.

What it is

Classes combine behavior with state.

When to use it

Represent domain concepts or collaborating components.

Syntax

class User
{
    public function __construct(public string $name) {}
}

Example

$user = new User("Ada");
echo $user->name;

Common mistakes

A class named User does not provide authentication; public mutable properties allow changes.

Related topics

Constructors