georgeocrawford
Technical User
Hi,
Just wondering if I am going about this the best way.
I have divided a fairly extensive script up into functions, firstly to prevent having to print the same code twice, and secondly to help me keep control of my script.
The problem is that, for the vast majority of my functions, most of the variables inside have to be carried out, and visa versa. This means that I am having to declare a huge number of variables as 'global' in each function:
...function continues
Of course this becomes even more ridiculous when I call a function from inside another function, because I have to declare all the shared variables as 'global' in both the 'child' and the 'parent' functions.
I can see two possible solutions.
1) Some php function I haven't yet heard of which declares a set of variables as 'global' for the whole script (i.e. every constituent part of it, including all the functions).
2) Change the structure of my script - perhaps using classes (which I haven't yet learnt about).
Thanks for any help. ______________________
George
Just wondering if I am going about this the best way.
I have divided a fairly extensive script up into functions, firstly to prevent having to print the same code twice, and secondly to help me keep control of my script.
The problem is that, for the vast majority of my functions, most of the variables inside have to be carried out, and visa versa. This means that I am having to declare a huge number of variables as 'global' in each function:
Code:
function process_something() {
global $variable1, $variable2, $variable3, $variable4..... ;
Code:
}
Of course this becomes even more ridiculous when I call a function from inside another function, because I have to declare all the shared variables as 'global' in both the 'child' and the 'parent' functions.
I can see two possible solutions.
1) Some php function I haven't yet heard of which declares a set of variables as 'global' for the whole script (i.e. every constituent part of it, including all the functions).
2) Change the structure of my script - perhaps using classes (which I haven't yet learnt about).
Thanks for any help. ______________________
George