How can the EVA principle be applied to improve the structure of PHP scripts?

The EVA principle (Encapsulate, Validate, and Avoid) can be applied to improve the structure of PHP scripts by encapsulating related functionality into classes or functions, validating input data to prevent errors and security vulnerabilities, and avoiding unnecessary complexity or redundancy in the code.

// Encapsulate related functionality into a class
class User {
    private $username;

    public function setUsername($username) {
        $this->username = $username;
    }

    public function getUsername() {
        return $this->username;
    }
}

// Validate input data to prevent errors and security vulnerabilities
$username = $_POST['username'] ?? '';
if (empty($username)) {
    // Handle empty username error
}

// Avoid unnecessary complexity or redundancy in the code
$users = ['Alice', 'Bob', 'Charlie'];
if (in_array($username, $users)) {
    // User is valid
} else {
    // Handle invalid user error
}