Is there a way in PHP to pass variables from a function to the scope in which it was called? I understand that there is a return
, but I am interested in simply setting an external variable from a function (and except for $GLOBALS
).
|
1 answer
There are several ways:
- Through
$GLOBALS
. (although you don't like it) - Through
global $param
. (for some reason you didn't like it either) - Via
return array('param' => $param)
and parse it. - Through the transfer of the function of parameters as references:
function a(&$param){$param = 123;}
.
Did I forget something?
- Stop, №2 - it's the same for holding the variable IN function, is it not? Or does it create an external link inside? I need to change the external from the inside. - Oleg Arkhipov
|
return
, of course. But$GLOBALS
generally uncomfortable. - Oleg Arkhipov