NYCPHP Meetup

NYPHP.org

[nycphp-talk] global variables

Chris Snyder chris at psydeshow.org
Thu May 22 11:22:19 EDT 2003


Bhulipongsanon, Pinyo wrote:

>Hi all,
>
>I have questions regarding global.  It appears that my program that uses
>global no longer work consistently.  I think because global has been turned
>off in newer server.  I only need global variables so that functions can use
>them, however I really do not want to pass everything by value to the
>function.
>
>So this code is out:
>
>global $var1, $var2;
>
>  
>
That doesn't seem entirely right-- global $var1, $var2; should still 
work just fine. What's been turned off is probably "register_globals" 
which only applies to server environment and CGI request variables, not 
variables that you declare at runtime.

file:///usr/local/share/doc/php/configuration.directives.html#ini.register-globals

If either $var1 or $var2 are really $_GET['var1'] or $_GET['var2], then 
you'll need to explicitly assign them in global scope like so:

<?php

function foo() {
    global $var1, $var2;
    return $var2.$var1;
    }

$var1= $_GET['var1'];
$var2= $_SERVER['DOCUMENT_ROOT'];

?>

Should work...









More information about the talk mailing list