Variable scoping - issues with global and multiple includes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hrishikesh.mehendale@gmail.com

    Variable scoping - issues with global and multiple includes

    Hi All, Sorry if I'm just repeating other questions, but I can't find
    an answer for this particular problem: I have my main index.php file,
    which looks so: <?php include "includes/header.php"; #defines a global
    variable called $lang include "includes/functions.php"; # some required
    functions safe_include "main_page.html "; # user-defined function that
    tries to # include main_page.html. $lang
    or gives a warning message echo "Language available to index.php at
    line XYZ is -$lang-"; #-- to check empty value include
    "includes/footer.php"; #page footer ?> and header.php looks so: <?php
    global $lang; $lang = "en"; ?> footer.php looks like so: <?php echo
    "Language is set to -$lang-"; # should print out current language in
    use ?> Now the problem is, the $lang variable is available to all
    statements in between, upto and including the safe_include statement.
    Unfortunately, footer.php refuses to see the variable. What can be
    the problem? Thanks Hrishikesh

  • hrishikesh.mehendale@gmail.com

    #2
    Re: Variable scoping - issues with global and multiple includes

    argh! stupid gmail posting system that kills formatting !!!

    Reformatted, here is my original query:

    Hi All,

    Sorry if I'm just repeating other questions, but I can't find an answer
    for this particular problem:

    I have my main index.php file, which looks so:

    <?php

    include "includes/header.php"; #defines a global variable called $lang

    include "includes/functions.php"; # some required functions

    safe_include "main_page.html "; # user-defined function that tries to

    # include main_page.html. $lang or gives a
    warning message

    echo "Language available to index.php at line XYZ is -$lang-";

    include "includes/footer.php"; #page footer

    ?>

    and header.php looks so:
    <?php
    global $lang;
    $lang = "en";
    ?>

    footer.php looks like so:
    <?php
    echo "Language is set to -$lang-";
    ?>

    Now the problem is, the $lang variable is available to all statements
    in between, upto and including the safe_include statement.

    Unfortunately, footer.php refuses to see the variable. What can be the
    problem?

    Thanks Hrishikesh

    Comment

    • Tim Van Wassenhove

      #3
      Re: Variable scoping - issues with global and multiple includes

      On 2006-04-10, hrishikesh.mehe ndale@gmail.com <hrishikesh.meh endale@gmail.co m> wrote:[color=blue]
      > Now the problem is, the $lang variable is available to all statements
      > in between, upto and including the safe_include statement.
      >
      > Unfortunately, footer.php refuses to see the variable. What can be the
      > problem?[/color]

      You must have unset it somewhere. Otherwise it would still exist.

      --
      Met vriendelijke groeten,
      Tim Van Wassenhove <http://timvw.madoka.be >

      Comment

      Working...