CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Globals help

  1. #1
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Globals help

    I tried to read about global variables on tutorials but they only talking about globals in user created functions.
    So what i'd like to know is if i declare a variable in the main index file will it be global for the files that i include after?
    And is it the same for arrays?

    PHP Code:
    ...
    <?php
         $realpath 
    "G:\\hello.txt";
         
    $titles = array();
         include(
    "file1.php");
         include(
    "file2.php"); 
       
    ?>
    ...

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Globals help

    You could have tested it out just as easily yourself.

    In short...no. Variables from included files will be available in the PHP file calling the included files after the line in which the file is included. But, variables in the main file are not recognized within the included files.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Globals help

    I did test it before asking and was confused because i didnt get any error but still i couldnt change the
    values of the variable either.

    Now ive declared them in the included files like

    PHP Code:
        $realpath "G:\\hello.txt";
        
    $GLOBALS["realpath"];
        include(
    "switch.php"); 
    but i still cant change them in switch.php (included in the main included file).

    Edit: I did a small test and i realize that it works even without the $GLOBALS["realpath"]; so the problem must come from elsewhere.
    Last edited by MasterDucky; January 18th, 2011 at 10:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured