How does PHP have dynamic scope? It's been ages since I touched it, but if I remember right...
Global is just a flat namespace. Functions have their own, separate flat namespace each. I tried the following in a REPL:
function two() {
echo $a;
}
function one() {
$a = 1;
two();
}
one();
as the standard dynamic scope example, and I get an "undefined variable" error. Did that use to be dynamic? (I wouldn't be surprised, though, especially given PHP's implementation history...)
There is an explicit "static" modifier that looks dynamic, but I couldn't get it to run that way. It seems to just retain state in recursive calls of the same function, or something?
[edit:] (And PHP doesn't predate Javascript, but regardless, "no first-class functions" isn't "no lexical scope".)
Yeah, I shouldn't have used the term "dynamic scope" there. PHP has dynamic environments that can be mutated at runtime, which languages like JS don't (well, outside of direct eval).