header + global $var in function problem header + global $var in function problem
 

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

Main Menu

header + global $var in function problem

Started by gregory, August 12, 2009, 11:11:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

gregory

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.

Nibbler

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();

gregory

I know. It's just an example. Sure I call this function. That why I wrote "2. "

Nibbler


gregory

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?

gregory

I've found another problem.

"global $var;" is working but "global $var1, $var2" shows me only $var1.

gregory

I mean this global variables are working inside the function now but don't work outside this function as earlier)))

Nibbler

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();