3 ms·
The default scope within a function is not global, and all global variables are available within a function by using the keyword "global". You can also access
by jamroom 17y ago
The default scope within a function is not global, and all global variables are available within a function by using the keyword "global". You can also access the superglobals, but that of course is optional.
- jacquesm 17y agohacking the procrast to be able to answer you... The default scope is global, I did not say 'within a function'. I know about the 'global' keyword, as does everybody else that has used PHP for more than 5 minutes. If your language has a C like syntax and you have a default scope (which means that you can start executing code right from the first line without being in a function definition) then the default behaviour of a variable should be that it either does not exist inside a function (different scope) and throws an error or it should refer to the global variable. To have a 'third option', which silently creates empty variables is very (no, make that extremely) poor design. And no, I'm not telling how to break noprocrast :)