coppermine-gallery.com/forum

Support => cpg1.4.x Support => Older/other versions => cpg1.4 themes/skins/templates => Topic started by: gregory on August 12, 2009, 11:11:33 PM

Title: header + global $var in function problem
Post by: gregory on August 12, 2009, 11:11:33 PM
Hi,

I'm trying to use Coppermine Gallery on my website with my header.inc.php & footer.inc.php.
In "header.inc.php" file I include the file "function.inc.php". In "function.inc.php" I have a code below (just example):
$var99 = 50;

echo "1." . $var99;

function getVar()
{
  global $var99;

  echo "2." $var99;
}
The result is:1. 50
2.

What is the problem? All the variables are work but not inside the function when I define them through "global".
I'm testing this problem on the page: http://domain.com/gallery/thumbnails.php?album=1

Please help.
Title: Re: header + global $var in function problem
Post by: Nibbler on August 12, 2009, 11:58:46 PM
It's not in scope. Your code should be like this:


<?php

global $var99;

$var99 50;

echo 
"1." $var99;

function 
getVar()
{
  global 
$var99;

  echo 
"2." $var99;
}

getVar();
Title: Re: header + global $var in function problem
Post by: gregory on August 13, 2009, 12:01:44 AM
I know. It's just an example. Sure I call this function. That why I wrote "2. "
Title: Re: header + global $var in function problem
Post by: Nibbler on August 13, 2009, 12:05:52 AM
Did you try the code I posted?
Title: Re: header + global $var in function problem
Post by: gregory on August 13, 2009, 02:14:03 AM
Oh, I've missed the first "global".
Thank you very much! Everything is working.
Can you please describe me what was the problem? Is this header inside of another function or what?
Title: Re: header + global $var in function problem
Post by: gregory on August 13, 2009, 02:26:03 AM
I've found another problem.

"global $var;" is working but "global $var1, $var2" shows me only $var1.
Title: Re: header + global $var in function problem
Post by: gregory on August 13, 2009, 02:28:34 AM
I mean this global variables are working inside the function now but don't work outside this function as earlier)))
Title: Re: header + global $var in function problem
Post by: Nibbler on August 13, 2009, 12:18:52 PM
The code is included from within a function in Coppermine. Not sure what your issue with multiple globals is, works for me.


<?php

global $var1$var2;

$var1 50;
$var2 60;

echo 
"1. " $var1 '.' $var2;

function 
getVar()
{
  global 
$var1$var2;

  echo 
"2. " $var1 '.' $var2;
}

getVar();