What is the EVA principle in PHP and how does it apply to code organization?

The EVA principle in PHP stands for "Encapsulate, Validate, and Assert." This principle emphasizes the importance of encapsulating data, validating input, and asserting conditions to ensure code reliability and security. By following the EVA principle, developers can organize their code in a structured manner that promotes reusability, maintainability, and readability.

class User {
    private $username;

    public function setUsername($username) {
        // Validate input
        if (!is_string($username)) {
            throw new InvalidArgumentException('Username must be a string');
        }

        // Encapsulate data
        $this->username = $username;
    }

    public function getUsername() {
        // Assert condition
        if (empty($this->username)) {
            throw new Exception('Username is not set');
        }

        return $this->username;
    }
}

$user = new User();
$user->setUsername('john_doe');
echo $user->getUsername();