Is it advisable to use interfaces in addition to classes for type validation in PHP?

Using interfaces in addition to classes for type validation in PHP can be beneficial as it helps enforce a contract between classes, ensuring that certain methods are implemented. This can help improve code readability, maintainability, and reusability. By defining interfaces for type validation, you can create a clear structure for your code and make it easier to understand and work with.

<?php

interface ValidatorInterface {
    public function validate($data);
}

class EmailValidator implements ValidatorInterface {
    public function validate($data) {
        return filter_var($data, FILTER_VALIDATE_EMAIL) !== false;
    }
}

class NumberValidator implements ValidatorInterface {
    public function validate($data) {
        return is_numeric($data);
    }
}

$emailValidator = new EmailValidator();
$numberValidator = new NumberValidator();

$email = "test@example.com";
$number = 123;

var_dump($emailValidator->validate($email)); // Output: true
var_dump($numberValidator->validate($number)); // Output: true

?>