Re: Sub groups ? - Programming structure...

From: Date: Tue, 09 Apr 2002 13:50:41 +0000
Subject: Re: Sub groups ? - Programming structure...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-92231@lists.php.net to get a copy of this message
On Tuesday, April 9, 2002, at 09:47 AM, Gordon Stewart wrote:
Hello, - I'm used (in years gone by) to the Qbasic programme, where i can create 'sub' routines, & view each routine on its own - Without reference / Viewing the other code.. (I think its good like that..).. I know in CGI/Perl - you can use sub-routines etc... 1) Does PHP allow sub-routines, eg - I can send values to the routine, & it processes it & does whatever it requires & returns to the spot where I called it from. 2) For those of you that know Qbasic & know what i mean, is/are there any programmes out there that can allow you to view / see any sub-routines in Perl and/or PHP one at a time, & list them ..
I know what you mean -- I sometimes use functions to achieve the same effect, since I tend to have certain things like forms that need to be repeated. Here's a really simple example: function display_login() { // print the start of the form print("<form method=\"post\" action=\"targetpage.php\">\n"); print("Enter your user name:"); // print the <input> tag, and if user has a cookie // called 'loginname', use that as the value of the input if ($_COOKIE['loginname']) {
    print("<input name=\"login\" type=\"text\"
           value=\"" . $_COOKIE['loginname'] . "\" />\n");
} else { // no cookie, just print it normal
    print("<input name=\"login\" type=\"text\" />\n");
} // finish the form print("</form>"); // return true, so this function can be tested for success return true; } Now, say there are many places that you need to display this primitive login form. In each place, you could always just enter it as display_login() or even better, you could test to see if the function was successful and perform some action if it wasn't by doing if (!display_login()) { die("Could not display login form"); } Note that some might consider this a perversion of functions, since functions are intended to operate on input and return a value -- but this is a convenient way of modularizing your display code, and I use it a lot. Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com

« previous php.general (#92231) next »