Re: Help with Javascript: naming variables using other variables
- From: Michael Winter <m.winter@xxxxxxxxxxxxxxxx>
- Date: Mon, 07 Nov 2005 13:53:53 GMT
On 06/11/2005 17:54, X l e c t r i c wrote:
sagejoshua wrote:
[snip]
<?php $var1 = "foo"; ${$var1.bar} = "great!"; print $foobar; // Outputs "great!" ?>
[snip]
Are you sure that outputs "great!" ?
[snip]
To elaborate on what Leif wrote, the variable variable constructed above is made possible through string concatenation, similar to
var variable = 'foo';
this[variable + 'bar'] = 'Great!'; /* foobar = 'Great!'; */
in ECMAScript. However, rather than using a string literal, the OP has written in bar what would normally considered a constant. Indeed, if STRICT notices are enabled in PHP, this will be reported in the error log.
It would be better written as:
<?php
$variable = 'foo';
${$variable . 'bar'} = 'Great!';
print $foobar; /* Great! */
?>Mike
-- Michael Winter Prefix subject with [News] before replying by e-mail. .
- Follow-Ups:
- Re: Help with Javascript: naming variables using other variables
- From: sagejoshua
- Re: Help with Javascript: naming variables using other variables
- References:
- Help with Javascript: naming variables using other variables
- From: sagejoshua
- Re: Help with Javascript: naming variables using other variables
- From: X l e c t r i c
- Help with Javascript: naming variables using other variables
- Prev by Date: Re: multiple frame-update
- Next by Date: associate a hidden input to (chosen) select option in form?
- Previous by thread: Re: Help with Javascript: naming variables using other variables
- Next by thread: Re: Help with Javascript: naming variables using other variables
- Index(es):