Can someone explain to me what this PHP line is doing?
$fileName = (isset($_POST[self::$PARAM_FILE_NAME])) ? $_POST[self::$PARAM_FILE_NAME] : null;
Can someone explain to me what this PHP line is doing?
$fileName = (isset($_POST[self::$PARAM_FILE_NAME])) ? $_POST[self::$PARAM_FILE_NAME] : null;
$fileName = (isset($_POST[self::$PARAM_FILE_NAME])) ? $_POST[self::$PARAM_FILE_NAME] : null;
It sets the variable named $fileName to either the value of $_POST[self::$PARAM_FILE_NAME] or to null. Another way to write it is:
if (isset($_POST[self::$PARAM_FILE_NAME]))
$fileName = $_POST[self::$PARAM_FILE_NAME];
else
$fileName = null;
This avoids a warning if the key in $_POST isn't set, which would you get with the more straightforward version:
$fileName = $_POST[self::$PARAM_FILE_NAME];
That line is simply a shorthand php if|else
statement.
Expanded, it would look like this:
if(isset($_POST[self::$PARAM_FILE_NAME])) {
$fileName = $_POST[self::$PARAM_FILE_NAME];
} else {
$fileName = null;
}
You can read more about it here
.
It is basically a shorter assigning of the variable.