Reply to Re: Help with Javascript: naming variables using other variables

Your name:

Reply:


Posted by Michael Winter on 01/16/33 11:31

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.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация