I am trying to define a constant like in my code below for being able to easily switch between $_POST and $_GET without the need to change multiple lines.
But I get the following Error:
Parse error: syntax error, unexpected '[', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in /var/www/public_docs/admin/web_interface/contract.php on line 14
define(DEFAULT_DATA_METHOD, $_GET); // change to $_POST if post should be used
function getData($Name, $Default = "")
/// Encapsulate data retrieval from $_GET or $_POST
{
return (isset(DEFAULT_DATA_METHOD[$Name]) ? DEFAULT_DATA_METHOD[$Name] : $Default); <-- Line 14
}
Is what I want to achieve possible? And how?
You can't use define
with an array. The documentation is very clear about it:
value
The value of the constant; only scalar and null values are allowed. Scalar values are integer, float, string or boolean values.
You can use an ordinary reference variable:
$default_data_method =& $_GET;
Or you could use $_REQUEST
, which automatically merges $_POST
and $_GET
.