You are here: Re: =& when creating new object « PHP Programming Language « IT news, forums, messages
Re: =& when creating new object

Posted by Joe on 09/24/07 21:24

Right to left makes sense. Thanks.

I'm still unsure of cases where I should use & and where I should not,
but I guess that will come from reading more examples.


On Sep 24, 10:08 pm, "Steve" <no....@example.com> wrote:
> "gosha bine" <stereof...@gmail.com> wrote in message
>
> news:46f823bf$0$31121$6e1ede2f@read.cnntp.org...
>
>
>
> > Shelly wrote:
> >> "Steve" <no....@example.com> wrote in message
> >>news:r6VJi.36$Nr6.32@newsfe05.lga...
> >>> "Joe" <j...@faceh.com> wrote in message
> >>>news:1190663828.772978.15800@22g2000hsm.googlegroups.com...
> >>>> I am just starting to use Object Oriented PHP coding, and I am seeing
> >>>> quite often the following (this example taken from a wiki):
>
> >>>> $wakka =& new Wakka($wakkaConfig);
>
> >>>> What exactly is the =&, and why is it different from = ?
> >>> well, better syntax would have helped. it should read ' $something =
> >>> &$variable'. in this context, & means 'a reference to the memory
> >>> location where the value is stored'. without the &, it means 'a copy of
> >>> the value of the variable'.
>
> >>> clear as mud? rather than explain memory, let me have you do this:
>
> >>> $variable = 'hello';
> >>> $reference = &$variable;
> >>> $variable = 'world';
> >>> echo '<pre>' . print_r($reference, true) . '</pre>';
> >>> $reference = 'good-bye';
> >>> echo '<pre>' . print_r($variable, true) . '</pre>';
>
> >>> unset($variable);
> >>> unset($reference);
>
> >>> $variable = 'hello';
> >>> $reference = $variable;
> >>> $variable = 'world';
> >>> echo '<pre>' . print_r($reference, true) . '</pre>';
> >>> $reference = 'good-bye';
> >>> echo '<pre>' . print_r($variable, true) . '</pre>';
>
> >>> the first example, BY REFERENCE, means that both $variable and
> >>> $reference point to the same memory location. changing one but using the
> >>> other makes no difference - using either will have the same effect.
>
> >>> the second, BY VALUE, means that each variable points to two different
> >>> locations in memory. the only time they will be equal is when setting
> >>> them so. once you modify one of them, you have done so idependently of
> >>> the other - changing one has no effect on the other.
>
> >>> hope that makes more sense.
>
> >> That was probably the single most unique new concept (pointers and
> >> address-of) I had conquer when (os so many years ago) I learned C, coming
> >> from a Fortran background as I did.
>
> >> Shelly
>
> > php references have nothing to do with C-alike pointers.
>
> > Please read the chapter called "references are not pointers" in the
> > manual.
>
> 'chapter' ? oh, you mean the quoted text of a usenet post? may i ask, who is
> jani?
>
> " For the 2nd time: references ARE NOT POINTERS! :-p
>
> --Jani
> "
>
> hmmm, i see the strong case being made here! kind of like:
>
> "for the nth time! toothfairies ARE REAL!"
>
> gosha, you'd be wise at this point to draw the distinctions yourself (if not
> capable, use a supported reference [no pun]). but, since references provide
> identical behaviors to pointers, the only difference that i see is the
> literal words themselves (one, 'pointer', the other, 'reference')...and
> perhaps some symantics somewhere.
>
> as it is, REFERENCES like POINTERS speak to POINTING TO AN ADDRESS or a COPY
> OF A VALUE AT AN ADDRESS...which is EXACTLY WHAT A POINTER IS/DOES. not to
> mention that AT LENGTH, php has discussed that the biggest change/hurdle
> when moving from php < 5 to php >= 5 will be how objects are going to be
> passed BY REFERENCE instead of byVal from here on out.
>
> however, since you don't like me calling you an idiot when i see you being
> one, you have killfiled my responses...like a child. so, you won't even feel
> corrected. if you do read this post, and not being able to provide a valid
> counter, you'll pretend not to see this post out of shear convenience...and
> the side-effect of saving face.

 

Navigation:

[Reply to this 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

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