Why cant I access $_POST variable with a hyphen/dash in its key if passing key as variable?

前端 未结 2 1855
小鲜肉
小鲜肉 2021-01-25 00:40

I\'ve written a small static method for my class which returns either $_POST variable if it is set or NULL otherwise. Input elements in HTML form have

2条回答
  •  醉话见心
    2021-01-25 01:11

    This may be a limitation of PHP - when using superglobals such as $_POST, there are some "magical" things going on. PHP converts the names of form elements in many ways, for example

    
    

    Will be accessible as $_POST['hello']['mate'], because the form names are processed as variables. Using dashes is therefore generally not a good idea, because they are not allowed in variable names and probably interfere here. I would advise to only use characters which are allowed for variables in PHP, and replace dashes with underscores.

提交回复
热议问题