Results 1 to 7 of 7

Thread: [Resolved] ***? Global problem...

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [Resolved] ***? Global problem...

    I'm doing this sort of thing in numerous scripts, however, in ONE FILE, it's not working.

    Here's a condensed version of the code:

    Code:
    <?php
    
        $CONFIG['absolute_path'] = '/home/vbshelf/public_html/reality/news/';
        //config.php simply loads some variables from a database
        //into the $CONFIG array:
        include $CONFIG['absolute_path'] . 'config.php';
    
        echo $CONFIG['numitems'] . '<br>'; //WORKS!
    
        function _news($cat = '') {
            global $CONFIG;
            
            echo $CONFIG['numitems'] . '<br>'; //DOESN'T WORK?
        }
    
    ?>
    What gives?!
    Last edited by The Hobo; Aug 17th, 2003 at 09:44 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    This doesn't make any sense whatsoever...

    Anybody...?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I fixed it. I don't know how...but it works.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    the only thing I can see if it doesn't work is if you didn't run that function. but seeing how it is resolved then cool

  5. #5

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    the only thing I can see if it doesn't work is if you didn't run that function. but seeing how it is resolved then cool
    I was running the function. Matt and I spent like an hour trying to figure it out, and then I changed one small thing (in a file we weren't even looking at) and it worked. Still didn't make sense, but...oh well.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    I had this problem a little while ago. I had a function that included the file which had my variable in it. So at the top of my file with the variable, I added "gloabl $myvar" and when the function went to include the file everything was fine. I had something like this:

    PHP Code:
    function incFunc()
    {
        
    $files = array("file1.php""file2.php");
        foreach(
    $files as $file)
        {
            include(
    $file);
        }
    }

    // file1.php, example

    global $config;
    $config = array("var" => "variable""welcome" => "bonjour"); 

  7. #7

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Pretty much sounds like what I had to do to fix it.

    Crazy thing was that it worked fine on my PC, but didn't work on my host's server.
    My evil laugh has a squeak in it.

    kristopherwilson.com

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