Posted by ZeldorBlat on 12/08/05 01:25
Chung Leong wrote:
> ZeldorBlat wrote:
> > Chung Leong wrote:
> > > Is there anything funcationally difference between the following
> > > snippets:
> > >
> > > // first
> > > $lines[] = array();
> > > $line =& $lines[count($lines) - 1];
> > >
> > > // second
> > > $line = array();
> > > $lines[] =& $line;
> > >
> > > They should do the thing. A voice in my head though is saying there's a
> > > subtle difference.
> >
> > They look the same to me -- at the end of the day both $line and
> > $lines[0] point to the same, empty array. Of course #2 is more
> > readable and straightforward.
>
> I think you're right. My concern was that in the first block, an array
> was added to $lines, while in the second, a reference was added.
> Momentarily I forgot that references don't exist as discrete objects.
>
> Thanks.
Yeah -- I like PHP's reference model a lot, mainly for it's simplicity:
every single "variable" is just a "label" for some value in memory.
Creating a "reference" is really just a way of creating another label
for that same value in that same spot in memory. Of course there are
some rules about what is always assigned by reference and what is
always copied.
[Back to original message]
|