* and then Robert Cummings declared....
> On Wed, 2006-07-12 at 18:52, Nick Wilson wrote:
> > hi all, 
> > 
> > After upgrading a CMS, im having a problem with global variables not
> > showing up anymore -- configs and things could have changed, but search
> > as i have, i cannot find anything to help me work out what the problem
> > is. 
> > 
> > This should work of course:
> > 
> >     $foo = 'bar';
> > 
> >     function foobar() {
> >       global $foo;
> >       print(" ------ " . $foo);
> >       exit;
> >     }
> > 
> >     foobar();
> > 
> > It prints *nothing*. Does anyone have an idea as to what might stop this
> > from functioning as expected?
> 
> The above code is probably being included, and probably being included
> by a function and so $foo does not have global scope. To ensure global
> scope:
> 
> <?php
>     $GLOBALS['foo'] = 'bar';
> 
>     function foobar()
>     {
>         global $foo;
>         print( " ------ " . $foo );
>         exit;
>     }
> 
>     foobar();
> ?>
> 
> Try that and let us know what happend.

No, it didn't work. It's odd, becuase it worked just fine in the
previous version, and this is a module, so that module is exactly the
same as the previous one -- ie i've not made any changes to do with
includes to it (just a few upgrades to form functions and stuff). 

I have fixed the issue, but the mystery will probably have to remain as
there is a lot more to do in the upgrade :( In the end i just manually
set $GLOBALS as you suggested and did a search and replace on the var to
do $GLOBALS[var] instead of global var; do_stuff($var);

crap i know, but thanks for the response!

-- 
Nick Wilson
http://performancing.com/user/1

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to