Among $_REQUEST, $_GET and $_POST which one is the fastest?

后端 未结 15 2254
小鲜肉
小鲜肉 2020-11-22 05:04

Which of these code will be faster?

$temp = $_REQUEST[\'s\'];

or

if (isset($_GET[\'s\'])) {
  $temp = $_GET[\'s\'];
}
else          


        
15条回答
  •  -上瘾入骨i
    2020-11-22 05:41

    $_REQUEST, by default, contains the contents of $_GET, $_POST and $_COOKIE.

    But it's only a default, which depends on variables_order ; and not sure you want to work with cookies.

    If I had to choose, I would probably not use $_REQUEST, and I would choose $_GET or $_POST -- depending on what my application should do (i.e. one or the other, but not both) : generally speaking :

    • You should use $_GET when someone is requesting data from your application.
    • And you should use $_POST when someone is pushing (inserting or updating ; or deleting) data to your application.

    Either way, there will not be much of a difference about performances : the difference will be negligible, compared to what the rest of your script will do.

提交回复
热议问题