Validation
Validation via the validate Method
validate Methoduse Astral\Serialize\Serialize;
class TestConstructValidationFromSerialize extends Serialize
{
public string $type_string;
/**
* Data validation method
* Automatically called after object creation via the from method
*/
public function validate(): void
{
// Validate the value of the type_string property
if ($this->type_string !== '123') {
throw new Exception('type_string must be equal to 123');
}
// You can also modify property values
$this->type_string = '234';
}
}Validation in __construct
__construct最后更新于