---
title: "Classes"
canonical_url: "https://handbook.propay.co.za/php/classes"
---
# Classes

## Name resolution

Do not use hardcoded fully qualified class names in code. Instead, resolve them via the `ClassName::class` keyword.

<code-group>

```php [PHP]
// GOOD
use App\Models\Order;
echo Order::class;

// BAD
echo 'App\Models\Order';
```

</code-group>

## Self keyword

Use the class name instead of the `self` keyword for return type hints and when creating an instance of the class.

<code-group>

```php [PHP]
// GOOD
public function createFromName(string $name): Tag
{
    $tag = new Tag();
    $tag->name = $name;

    return $tag;
}

// BAD
public function createFromName(string $name): self
{
    $tag = new self();
    $tag->name = $name;

    return $tag;
}
```

</code-group>

`return self` / `new self()` vs `return ClassName` / `new ClassName()` — we can use both, but it is better to be consistent.


## Sitemap

See the full [sitemap](https://handbook.propay.co.za/sitemap.md) for all pages.
