How exactly is PHP creating superglobal $_POST, $_GET, $_COOKIE and $_REQUEST?

后端 未结 4 1888
遥遥无期
遥遥无期 2021-02-02 11:38

I\'m sorry for confusing title of the question, I\'ll try to clarify what the issue is.

I\'m doing some work with Mongrel2 server and I\'m writing a PHP handler that has

4条回答
  •  忘了有多久
    2021-02-02 11:50

    $_POST, $_GET, $_COOKIE and $_REQUEST are available in PHP every time, also if php was run in command-line. These arrays are writable, you can add values to $_POST array and get one in any other places.

    This code fully correct and workable if run it from console:

    Result:

    $_POST in global scope:
    array(1) {
      'test' =>
      string(1) "1"
    }
    $_POST in function scope:
    array(1) {
      'test' =>
      string(1) "1"
    }
    Others super-global array in function scope:
    array(0) {
    }
    array(0) {
    }
    

    Edit

    Also, you can create class, and save data from HttpRequest in static field of it. In this case, you can use it from anywere.

提交回复
热议问题