Topics

User Functions

Events

There are no upcoming events

What's New

Stories

No new stories

Comments last 2 weeks

No new comments

Trackbacks last 2 weeks

No new trackback comments

Links last 2 weeks

No recent new links

NEW FILES last 14 days

No new files

Welcome to Geeklog Tuesday, May 21 2013 @ 03:36 PM EDT


 Forum Index > Support > General Geeklog Support New Topic Post Reply
 Static page and global variables
   
cmm
 08/11/09 10:04AM (Read 616 times)  
+----
Newbie
confused

Status: offline


Registered: 08/11/09
Posts: 1
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

PHP 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.

 
Profile Email
 Quote
Dirk
 08/11/09 04:07PM  
AAAAA
Admin

Status: offline


Registered: 01/12/02
Posts: 13027
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

 
Profile Email Website
 Quote
Content generated in: 1.18 seconds
New Topic Post Reply

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