SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    May 2003
    Location
    nyc
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what does "=&" mean in "$something =& new Something;"?

    hi all

    the subject says it all. what does "=&" mean when creating an instance of Something? Thanks a lot

    james

  2. #2
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you use a & you are passing a reference to the original variable, rather than creating a copy of it.

    If you do: $foo =& $bar;

    You have created an 'alias' of $bar, called $foo. If you change the value of $foo, then $bar will also change.

    If you do $foo = $bar, you have created a copy of $bar, and if you alter the value of $foo then $bar will not be changed.

  3. #3
    SitePoint Guru
    Join Date
    Oct 2001
    Posts
    656
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just want to add to that that doing $foo = $bar does not create an actual in-memory copy of the object's value. i.e. if you have a 2 megabyte array in memory and you do $foo = $bar, you won't have two 2 megabyte arrays in memory all of the sudden.

    See http://zend.com/zend/art/ref-count.php

  4. #4
    SitePoint Addict
    Join Date
    May 2003
    Location
    nyc
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot guys.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •