Forum Moderators: coopster
isset($_POST['foo'])? $foo = $_POST['foo'] : $foo = '';
I use it in an email form I have, it's at the very top of my code. I know it was important to use this when I changed the form from PHP4 to PHP5 - without it, all kinds of error messages came up when using PHP5 (when error reporting was turned on - but it didn't mess with the functionality of the form - just gave an error). "foo" would be anything that was a variable in the form (such as "action", "submit" and "error" to name a few, then the end-user's input into the form)
I can't seem to find an actual "layman's term" definition of what this line actually does. I know it's saying "If foo is posted from the form, and it's set as something, then..." but from there, I'm lost as to what it really means.
If someone could give me a simple explanation of this line, I'd appreciate it! Thanks!
When your script expected a defined $foo, it would throw an error if it was not defined. The line prevents the error from happening.
Ancient species of PHP would automically convert variables used in requests, either GET or POST or COOKIE, to local values like $foo. Somewhere in the evolution of PHP4 it was decided that this was insecure behaviour and should be banned. The change was implemented gradually and in your case probably became effective when you upgraded to PHP5.
from the link
The expression (expr1)? (expr2) : (expr3) evaluates to expr2 if expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE.