...

View Full Version : $$ variable



arjaya
10-22-2004, 08:20 PM
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!

dswimboy
10-22-2004, 08:43 PM
$$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/codecorn/littperl/perlsub.htm#References

marek_mar
10-22-2004, 08:46 PM
http://www.php.net/manual/en/language.variables.variable.php

arjaya
10-22-2004, 09:45 PM
Excellent Thank you!

arjaya
10-22-2004, 09:52 PM
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:



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!

marek_mar
10-22-2004, 10:01 PM
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.

arjaya
10-22-2004, 11:11 PM
Thats what i expected. It just seemed odd that they made a wrapper function for php defined functions.

Thanks for all your help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum