# Cast

> Forces custom casting before native property type casting.

[API reference](/docs/api/index.md) › [Model](/docs/extensions/model/reference/index.md) › [Attribute](/docs/extensions/model/reference/attribute/index.md) › Cast

| final readonly class | `UIAwesome\Model\Attribute\Cast` |
| --- | --- |
| Source | [`src/Attribute/Cast.php`](https://github.com/ui-awesome/model/blob/main/src/Attribute/Cast.php#L16) |

Forces custom casting before native property type casting.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-separator"></span>`$separator` readonly | `string` | Separates string items when casting to an array. | `Cast` |
| <span id="property-target"></span>`$target` readonly | `string` | Identifies the cast type or custom caster class. | `Cast` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Configures a nonempty cast target and array separator. | `Cast` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(string $target, string $separator = ',')
```

Configures a nonempty cast target and array separator.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$target` | `string` | Cast type or custom caster class. |
| `$separator` | `string` | Nonempty separator for array casts. |

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): When the target or separator is empty.