How can the use of a Request object simplify the handling of data from various sources in PHP projects compared to global evaluation of superglobal variables?

Using a Request object can simplify the handling of data from various sources in PHP projects compared to global evaluation of superglobal variables by encapsulating the data retrieval logic and providing methods for accessing and manipulating the data in a more controlled and organized manner. This helps improve code readability, maintainability, and security by reducing direct access to superglobal variables.

class Request {
    private $data;

    public function __construct() {
        $this->data = array_merge($_GET, $_POST);
    }

    public function get($key) {
        return $this->data[$key] ?? null;
    }

    public function has($key) {
        return isset($this->data[$key]);
    }

    public function all() {
        return $this->data;
    }
}

$request = new Request();
echo $request->get('username');