Reply to Re: =& when creating new object

Your name:

Reply:


Posted by Steve on 09/24/07 21:55

"Michael Fesser" <netizen@gmx.de> wrote in message
news:qgbgf3ljt4mdpeto9n4jaigkv460bnn2uu@4ax.com...
> .oO(Steve)
>
>>"Michael Fesser" <netizen@gmx.de> wrote in message
>>news:60agf3dds15g16okej94srele60sifocfu@4ax.com...
>>>
>>> Correct, but that's not what a reference does.
>>
>>you take all the fun out of this micha!
>
> Soooorry.
>
>>i wanted gosha to say all of that.
>
> OK. Gosha! Repeat after me ...
>
> SCNR
> Micha

micha,

i've been perplexed by this one, since we're talking about &. i think i know
the answer but cannot get confirmation. look at this:

<?
function buildOptionList($display, $value, &$options)
{
$options[1][] = '<option value="' . $value . '" ' .
($value == $options[0] ? 'selected' : '') .
'>' . $display . '</option>';
}
$categories = array(
'BODY' => 'BODY' ,
'FRAME' => 'FRAME' ,
'MECHANICAL' => 'MECHANICAL' ,
'PAINT' => 'PAINT'
);
$options = array();
$optionList = array('MECHANICAL', &$options);
array_walk($categories, 'buildOptionList', $optionList);
?>

let's say that's an abstract way to build a select option list using
array_walk. the user data argument that i want to use is an array. i want to
make additions to the array, so i use the & instruction. however, i cannot
just pass $options to array walk or it won't work. i think this has to do
with array_walk seeing $options as unitialized...user data is not being
passed a reference. i think what makes it work is the fact that an empty
string gets allocation. by passing an initialized string as part of an
array, optionList, then 'memory' is allocated for both members of
optionList.

does that sound right, or do you have another take on it? just
wondering...i've been puzzled at the explanation for a while.

[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

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