Welcome to Geeklog, Anonymous Friday, April 26 2024 @ 04:41 pm EDT

Geeklog Forums

Static page and global variables


Status: offline

cmm

Forum User
Newbie
Registered: 08/11/09
Posts: 1
confused
I am having a problem with global variables in a static page. I have a static page set up to run php, and the only code is "include (myfile.php);"

myfile.php looks something like

Text Formatted Code

<?php
function1()
{
  global $tvar;
  global $urlvariable;
  echo $tvar;
  echo $urlvariable;
}
$tvar ="1234";
$urlvariable = $_GET['urlvariable'];
function1();
?>
 


inside function1, echo $tvar is null, and echo $urlvariable is correct

The fun part is if I load the script outside of static pages, tvar works. But inside static pages the scope seems to change.

My first though to fix this is to call tvar as a argument to function1, but I'd rather not have to, as I'd like to know what's causing this.

Thanks for any help.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
The PHP code in a static page is itself run in the context of a function. So "global" may not be as global as you think ...

bye, Dirk
 Quote

All times are EDT. The time is now 04:41 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content