It's not a great practice but super common. I have seen code like
$i = "j": $$i = 3;
WTF?
$i = "j": $$i = 3;
WTF?
int a = 1; int *b = &a; *b = 2;
If this can be compiled to efficient assembly, I don't think that kind of variable binding presents much more of a challenge.All this is essentially a double hashtable lookup (assuming the lexical environment is implemented as a hashtable, but if it's something else, it's similarly trivial):
environment[environment["i"]] = 3
People have been compiling extremely dynamic languages since the Lisps, at the very least; and, assembly itself isn't really a "statically typed" language. $x=0;$a='x';$b='a'; echo $$$b; $x = 'y';
$y = 'x';
echo $$$$$$$$$$$$$y;
I've tested with 1500 `$` and it still works :) foreach(['a' => closureA, 'b' => closureB, 'c' => closureC] as $name => $toApply) {
$myObject->${convertNameToFieldName($name)} = $toApply($something);
}I hate stuff like that. It breaks more than it helps. It overcomplicates trying to dance your way through reasoning what is actually happening. It’s unreliable and I hate it.
Carry on...