Structure/Vairables Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dila125
Forum Newbie
Posts: 7
Joined: Fri Apr 09, 2004 7:11 am

Structure/Vairables Problem

Post by dila125 »

Hi,

I have a problem with the structure of my website which is causing problem
with passing variables between functions, even when declared as global.

It would probably be easiest if I explain the structure in english instead
of listed loads of code:

page.php
include output.php
display header
display main
display footer
function content

output.php
function display header
function display main (table with menu on left and displays content from
main page on right)
function display footer

I have choosen this structure so the main layout for the site is all store
in function on a single page. The individual pages then contain a function
with their own content which is placed in the appropriate place by the
function in output.php

This works ok, the problem is with variables. If I declare a global variable
at the top of page.php, it will work fine within that page, but if I try to
call it within the content function, which is called through the output
file, then the variable is empty.

Has anyone got any better ideas for a structure which would solve the
variable problem?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

If I declare a global variable at the top of page.php
How are you declaring a global variable?

You should really just need:
$var = 'foo';
include 'output.php';
(then in output.php)
function content(){
global $var;
//do whatever with $var
}

If i've misunderstood the exact layout then maybe some code snippets would help ;)
Post Reply