using functions to break down a large task I'm having difficulty getting my head around
that's all the more reason to NOT break encapsulation that is provided by functions.
a function should only interact with the calling code at the point where the function is being called. if you read the calling code, you should be able to see what values are being supplied as inputs (the call time parameters), the function name itself indicates what the function does, and any result is returned at the point where the function is called. once you write and test your function, you should be able to forget what the actual code and variables in it are. it becomes a black box, reducing the amount of information you must actively keep track of when coding.
by using global variables inside a function, you must now keep track of which functions use which variables and you can no longer tell just by looking at the calling code what inputs a function uses (a week or a month from now, this will be important because you will have forgotten exactly what you did in each function and you shouldn't need to remember exactly what you have done in each function.) this doesn't reduce the amount of information you must keep track of, it actually makes more work for you.
an example using your checkvariable() function in the first post. a month from now, when you try (or someone else tries) to figure out what your code is doing, which would you rather see in your code -
checkvariable(); // check what variable? i guess i'll need to find and read or remember what the checkvariable function is to find out.
checkvariable($_GET['checkvar']); // check the $_GET['checkvar'] in this call
checkvariable($_POST['checkvar']); // check the $_POST['checkvar'] in this call
Edited by mac_gyver, 18 July 2013 - 10:49 AM.