Do I have to check whether the $_SERVER variable has a key REQUEST_METHOD before actually using $_SERVER['REQUEST_METHOD']?
That is, is it overly defensive to always check whether a key exists in array variable like $_SERVER?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The PHP-manual says the following about the $_SERVER-variable:
The CGI/1.1 specification has the following to say:
and
It probably isn’t necessary to check for its existense if you aren’t doing any CLI-development and the script will only be run from a server like Apache. You could probably do it, to be on the safe side, but it is of no necessity.