SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: =&

  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    =&

    I have been reading the PHP Anthology, and the author uses =& or = &new a lot but doesn´t explain why. So my question is why use =& or = &.

    Is there a diffrece between:
    $db = &new MySQL($host, $dbUser, $dbPass, $dbName); //Used in the book
    and:
    $db=& new MySQL($host,$dbUser,$dbPass,$dbName); //Used in the downloaded code archive
    eg: diffrence between = &new ---- =& new

    Sorry about the newbi Q.

  2. #2
    Obsessive designer Infizi's Avatar
    Join Date
    May 2004
    Location
    North Pole
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe, not a noob question, i sawe somwone using & in some code yesterday, like if( $variable& ),

    curious what it is all about..?

    I dont think it will be different having =& new or = &new tho...
    New Design - PHP Slowly flowing in!

    Infizi Studio's

  3. #3
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Örebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Yes, there is a difference between =& and = &new but not between =& and = & (it is just a matter of taste; some people put the & right after the assignment operator and some do not). The first one is used to add a reference to a variable, array key, object etc. while the second one is used when you create a new instance of a class (only necessary to use in PHP4; in PHP5, it is done automatically).

    Here is a simple example of how variable references work:

    PHP Code:
    $foo 'Hello World';
    $bar = &$foo;

    $bar strtr($bar'o''a');
    echo 
    $foo// prints out "Hella Warld" 
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.


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
  •