简体   繁体   中英

Why do we need specific classes to work with Request and Response?

I want to understand why we need specific classes to work with Request and Response. What's wrong with global variables like $_POST, $_GET, etc... Why is better and what's the problems it solves?

edit 1: Thank you, I know about PSRs. But the real question why is it bad? I don't think that the using $_GET, $_POST, etc is bad. Because why we would change its values?

As mentioned here :

The Request class is an object-oriented representation of the HTTP request message. With it, you have all the request information at your fingertips

and

As a bonus, the Request class does a lot of work in the background that you'll never need to worry about. For example, the isSecure() method checks the three different values in PHP that can indicate whether or not the user is connecting via a secured connection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM