Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: $$ variable

  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    $$ variable

    Hello,
    This may be a simple question that I have yet have an answer. What purpose does the following line of code achieve?

    global $$link;

    What does the double '$' in front of the link variable do? I'm new to php and have been looking at example code and came across this.

    Thanks!

  • #2
    Regular Coder dswimboy's Avatar
    Join Date
    Nov 2003
    Location
    mostly in Ann Arbor
    Posts
    458
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $$link is a variable. $link is called a reference variable. References are really rather confusing, and i wouldn't recommend using them unless you have to. i wouldn't recommend learning much about them either. i'm sure O'Reilly has a book on the topic, and i found a site on the topic. my native language is Perl, but it is extremely similar to PHP. the concept is all that counts here anyway. http://www.troubleshooters.com/codec...htm#References
    "There is more than one way to do it."

  • #3
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts

  • #4
    New Coder
    Join Date
    May 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Excellent Thank you!

  • #5
    New Coder
    Join Date
    May 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I actually saw this particular instance while looking through some osCommerce PHP code in the database.php functions.

    Here is a snippet of 2 functions from the .php file:

    Code:
    function tep_db_connect($server = DB_SERVER, 
                                       $username = DB_SERVER_USERNAME, 
                                       $password = DB_SERVER_PASSWORD, 
                                       $database = DB_DATABASE, $link = 'db_link')
    {
        global $$link;
    
        if (USE_PCONNECT == 'true')
        {
          $$link = mysql_pconnect($server, $username, $password);
        }
        else
        {
          $$link = mysql_connect($server, $username, $password);
        }
    
        if ($$link) mysql_select_db($database);
    
        return $$link;
    }
    
      function tep_db_close($link = 'db_link') {
        global $$link;
    
        return mysql_close($$link);
      }
    Also, why do would they create wrapper functions as seen above and use these wrapper functions throughout the whole scope of the osCommerce site?

    Thanks again!

  • #6
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    The idea of wrapper function is that when you want to change something in that particular piece of code you can do it in one place instead of everywhere the piece of code is used.

  • #7
    New Coder
    Join Date
    May 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thats what i expected. It just seemed odd that they made a wrapper function for php defined functions.

    Thanks for all your help!


  •  

    Posting Permissions

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