PHP 8.4 Property Hooks And Validation Examples
PHP 8.4 property hooks explained: validating user input with classes, traits & attributes. Centralize validation methods for recurring patterns.
I have written a post about the php 8.4 property hooks. Where I didn't understand what it did. And I added validation code examples that have nothing to do with it. So I did rewrite the post. But I didn't want to lose the valid example code. And that is why this post exists. What is the desired result? We want to create a user by first and last name. The name parts should not be empty because we assume everyone has a first and last name. Validation with a class method class User { public function __construct(private string $firstName, private string $lastName) {...