PFMaBiSmAd Posted September 25, 2010 Share Posted September 25, 2010 There nothing special about the $_POST variables. You can write your own values to them, so you don't have to do 1, 2, or 3 in your list if you don't want to. If you are going to be making multiple references to a variable during specific processing of it, it does save a little typing to make a copy of a $_POST variable into a regular program viable. However, be careful of any use of variable variables or extract to blindly create program variables from ALL the $_POST variables as that will allow a hacker to set any of your existing program variables to any value he wants, so it is possible to screw up the execution of your code. If you use variable variables/extract like this, you should always prepend a prefix name to the variables so that they cannot overwrite any of your existing program variables. Quote Link to comment Share on other sites More sharing options...
TomTees Posted September 25, 2010 Author Share Posted September 25, 2010 There nothing special about the $_POST variables. You can write your own values to them, so you don't have to do 1, 2, or 3 in your list if you don't want to. If you are going to be making multiple references to a variable during specific processing of it, it does save a little typing to make a copy of a $_POST variable into a regular program viable. However, be careful of any use of variable variables or extract to blindly create program variables from ALL the $_POST variables as that will allow a hacker to set any of your existing program variables to any value he wants, so it is possible to screw up the execution of your code. If you use variable variables/extract like this, you should always prepend a prefix name to the variables so that they cannot overwrite any of your existing program variables. So let's assume I want/need my own variables. Is it better to define variables in advance in my class, and then just map the $_POST variables to my variables? Or should I create my variables and my variables' values on the fly? And how much better is defining my own array? Because I am a procedural programmer by nature, I would usually just do: $email = $_POST['email']; $password = $_POST['password']; $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; But if I wanted to use an approach that could be re-used, then maybe dynamically creating variable names or using my own array is more flexible? TomTees Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.