Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: header + global $var in function problem  (Read 4653 times)

0 Members and 1 Guest are viewing this topic.

gregory

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
header + global $var in function problem
« 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):
Code: [Select]
$var99 = 50;

echo "1." . $var99;

function getVar()
{
  global $var99;

  echo "2." $var99;
}
The result is:
Code: [Select]
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.
Logged

Nibbler

  • Guest
Re: header + global $var in function problem
« Reply #1 on: August 12, 2009, 11:58:46 pm »

It's not in scope. Your code should be like this:

Code: [Select]
<?php

global $var99;

$var99 50;

echo 
"1." $var99;

function 
getVar()
{
  global 
$var99;

  echo 
"2." $var99;
}

getVar();
Logged

gregory

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Re: header + global $var in function problem
« Reply #2 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. "
Logged

Nibbler

  • Guest
Re: header + global $var in function problem
« Reply #3 on: August 13, 2009, 12:05:52 am »

Did you try the code I posted?
Logged

gregory

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Re: header + global $var in function problem
« Reply #4 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?
Logged

gregory

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Re: header + global $var in function problem
« Reply #5 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.
Logged

gregory

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Re: header + global $var in function problem
« Reply #6 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)))
Logged

Nibbler

  • Guest
Re: header + global $var in function problem
« Reply #7 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.

Code: [Select]
<?php

global $var1$var2;

$var1 50;
$var2 60;

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

function 
getVar()
{
  global 
$var1$var2;

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

getVar();
Logged
Pages: [1]   Go Up
 

Page created in 0.02 seconds with 19 queries.