By default a PHP function uses
$_GET variables. Sometimes this function should be called in an situation where
$_GET is not set. In this case I will define the needed variables as parameter like:
To get an abstract code I tried something like this:
which results in an error:
Parse error: syntax error, unexpected T_VARIABLE
Is it impossible to define an default parameter by using an variable?
actionOne is called "directly" from an URL using the framework Yii. By handling the
$_GET variables outside this function, I had to do this on an central component (even it is a simple, insignificant function) or I have to change the framework, what I don't like to do.
An other way to do this could be an dummy function (something like an pre-function), which is called by the URL. This "dummy" function handles the variable-issue and calls the
No, this isn't possible, as stated on the Function arguments manual page:
Instead you could either simply pass in null as the default and update this within your function...
...or (better still), simply provide $_GET['ID'] as the argument value when you don't have a specific ID to pass in. (i.e.: Handle this outside the function.)