mem0ri Posted March 6, 2006 Share Posted March 6, 2006 The question is purely academic at this point...but I have a question about the valid use of a global variable and whether the following would work or error out:$x = 1;function myFunction($y = $x){ global $x; do stuff} Quote Link to comment https://forums.phpfreaks.com/topic/4219-globals-and-valid-use/ Share on other sites More sharing options...
Gaia Posted March 6, 2006 Share Posted March 6, 2006 Yes, that would work. That's basically what it is used for, using variables that were initiated outside of a function, inside a function.If that makes any sense :pI'm sure someone else can add some more to my try at answering your question. Quote Link to comment https://forums.phpfreaks.com/topic/4219-globals-and-valid-use/#findComment-14664 Share on other sites More sharing options...
mem0ri Posted March 6, 2006 Author Share Posted March 6, 2006 Right...my big question is on the: function myFunction($y = $x) part......because the global hasn't been declared within the function yet...and is operating as the default value of information passed into the variable......additional...slightly related question...let's say I have:function myFunction($y = $x, $b = "string", $n = 1)...and I want to call the function with somethin' like a myFunction("string")...where it will only change the default value of $b...leaving $y and $n alone......basically...is there a way to explicitly address to which value a function call sends its arguments? Quote Link to comment https://forums.phpfreaks.com/topic/4219-globals-and-valid-use/#findComment-14665 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.