RE: [PHP] subroutines?

From: Date: Thu, 09 Aug 2001 16:14:46 +0000
Subject: RE: [PHP] subroutines?
Groups: php.general 
Request: Send a blank email to php-general+get-62004@lists.php.net to get a copy of this message
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:creinig@mayn.de] Sent: Thursday, August 09, 2001 8:21 AM To: CGI GUY; php-general@lists.php.net 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: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#62004) next »