Open Source/plain-to-class/Advanced usage/Custom setter

Custom setter

If a field requires additional processing during its initialization, you can define a mutator. To define a mutator, define a set{Attribute}Attribute method on your class, where {Attribute} is the studly-cased name of the property you wish to access. This mutator will be automatically called when we attempt to set the value of the real_address attribute on the model:

class UserDTO
{
public int $id;
public string $real_address;
public function setRealAddressAttribute(string $value)
{
$this->real_address = strtolower($value);
}
}