Variable variables
Victor_B
Posts: 391
Are there variable variables in Qt? I googled a little bit and it seems like NO, but maybe I googled badly.
So, I asking about an analog of PHP's
$$varname = 5;
and about analog of this notation
$a{$varname} = 5;
or simple a{$varname}
Just interesting. Thanks.
Comments
"variable variables"? Do you mean like a C pointer, i.e. a variable that can indirectly refer to another value? It is not Qt that has to have them, but rather ECMAScript.
If so, I think it does, "references", but only for objects. You can wrap an object around whatever values you want, though. Verify this as I really don't know what I'm talking about, just something I think I remember from the dozen or so lines of Javascript I've ever actually written :)
I don't know C and don't used that in JS, but in PHP time to time. To be clear:
Ok, forget this... Seems like, only PHP can do this bullshit magic :))
Rob offers:
I used to call this 'macro substitution' as I first came across it in dBase II back in the 80s and that was what it was called. It's a useful feature but it can get a bit confusing!
Curly braces? Yes, it's a substitution. But $$ is "variable variables" in PHP. Confusing? Only if you use it like this:
Yep, I can put my "variable variables" into array... Thanks Richard and Rob.