---
title: "Named constructors"
canonical_url: "https://handbook.propay.co.za/php/named-constructors"
---
# Named constructors

Use named static constructors (aka "static factories") to encapsulate logic and data and create valid entities:

<code-group>

```php [PHP]
// Models\Team.php
public static function createFromSignup(AlmostMember $almostMember): Team
{
    $team = new Team();
    $team->name = $almostMember->company_name;
    $team->country = $almostMember->country;
    $team->save();

    return $team;
}
```

</code-group>

Reason: a robust API that does not allow developers to create objects in an invalid state (e.g. a missing parameter or dependency). A great video on this topic: [Marco Pivetta — «Extremely defensive PHP»](https://youtu.be/Gl9td0zGLhw?t=1238)


## Sitemap

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