i've noticed that $POST[variable] is the same as $POST['variable'];
is this just something that comes from configuration, or is it standard for PHPs associative variables? OR, is it just a stylistic thing?
thanks, ugasucks
Never don't use $_POST[variable]! It's very bad! Just turn on warnings/errors displaying in the php.ini and you will see why.
The manual specifically warns against using $_POST[variable]. Always use quotes.
Here is what can happen define('variable','something'); $_POST[variable] will now access the entry called 'something'.
Unfortunately, there is a lot of code which does not use quotes so it's easy to get confused. It works without quotes as long as there are no defines but it's dangerous.
You should only use $_POST without quotes if you print something...
echo "Your name is : $_POST[name]";
But, personnally, what I do is this :
echo "Your name is : " . $_POST["name"];
thanks everyone!!! it's good to get a nice solid "HELL NO" from everyone as a response. i just realized this morning that it was unsafe to have register globals on, so i changed that (and all my variables to $_POST[variable]). now that i know that that is a stupid thing to do, i'm going back to change 'em.
there should be a large disclaimer on PHP that says not to do this... or i guess PHP should be called "PHP-RTFM".
plonk(myself);
NO. You SHOULD keep register_globals to off!!!! Just use $_POST["variable"]!!!!
even more picky question-- should it be $POST['variable'] or $POST["variable"] or does it matter?
thanks for ignoring my ignorance.
In general, use 'variable'. When you use "variable", the php processor does a bit more work since it tries to replace things like $var with their value.
In the real world, you would probably never notice the performance difference. But it's an easy rule to follow and every little bit can help.