<[EMAIL PROTECTED]> wrote:
> As a new PHP convert, I ran into this same problem (below) yesterday while
> designing a form.  ASP programmers (if they're THINKING) will use subs to
> keep "if" blocks tidy.  In ASP, I'd use something like:
>
> If Request.ServerVariables( "REQUEST_METHOD" ) = "GET" Then
> DisplayForm
> Else
> SendFormData
> End If
>
> which at first I replaced with:
> if ( getenv( "REQUEST_METHOD" ) == "GET" ) {
>         display_form();
> } else {
>         send_email();
> }
> ...making functions out of what used to be subroutines.  All
well-and-good,
> except my global variables disappeared and nothing I could do (even
> declaring the few important ones explicitly global) seemed to allow me to
> get at the variable contents.

Bill,

You need to declare the variables global within each function that access
them or access the variable via the $GLOBALS array.

$var = 'something';

function go()
{
    return $GLOBALS["var"];
}

or

function go()
{
    global $var;

    return $var;
}

echo go();

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to