+ 3
What is the difference between scope in javascript and PHP?
i would like to know how scope works in both languages because it gets confusing sometimes .. for all i know , in JS, variables in the global scope are accessible everywhere in the program even when used inside functions .. but why is php producing an error when trying to do the same? isn't the whole idea of "global" is to be able to use something globally? i appreciate any elaboration ..
1 Réponse
+ 1
I think in PHP it is not possible to declare a global variable in function. But you can try to use something like $GLOBALS asociative array. Then you can add something new to the global scope from a function.