Hi again,

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.

I wound up compromising by sending just the bits I needed in the function
INTO the function like so:

$MyURI = $SCRIPT_NAME;
$TheFormVars = $HTTP_POST_VARS;
if ( getenv( "REQUEST_METHOD" ) == "GET" ) {
        display_form( $MyURI );
} else {
        send_email( $TheFormVars, $ThisWebServerFQDN );
}

Seems a bit tacky at first, but it works (properly!) and that's all that
counts.  I can do much more with PHP functions just as they are than I ever
could with ASP;  moreover, I have much more secure control of what gets
exposed where.  To me, a beautiful compromise since at no point is there
ever an actual email address exposed to the outside world.  My "Support
Topic" selection box contains arbitrary codes that allow me to generate the
appropriate email address on the fly.

Hope my experience will be helpful to other noobies making the Big
Transition.

Best regards,
Bill

-----Original Message-----
From: Christian Reiniger [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 09, 2001 8:21 AM
To: CGI GUY; [EMAIL PROTECTED]
Subject: Re: [PHP] subroutines?


On Wednesday 08 August 2001 01:37, CGI GUY wrote:
> How does PHP compensate for an apparent lack of
> traditional subroutines (as with Perl, etc.)? It seems
> like I'm going to have to script separate pages for
> ea. set of processes in my search (i.e., print FORM,
> print results for SEARCH,
> print DETAILS, etc.).  Please tell me I'm mistaken!

http://www.php.net/manual/en/functions.php
http://www.php.net/manual/en/function.require-once.php
http://www.php.net/manual/en/control-structures.switch.php
http://www.php.net/manual/en/language.oop.php

-- 
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)

"World domination. Fast." (Linus Torvalds about Linux)

-- 
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