Hi all:
When I used to program in Cobol, C & co., I managed to get clean an easy to read code:
// sample program
// main body:
global variables...
if(condition)
{
do_stuff_1();
}
else
{
do_stuff_2();
}
// functions
function do_stuff_1()
{
lots of code accesing global variables...
}
function do_stuff_2()
{
lots of code accesing global variables...
}
[/COLOR]
Now with PHP I find real trouble to do the same, due to GLOBAL variables not being able to be accessed from functions, unless I declare them especifically in every function (quite boring, error prone, and difficult to debug):
// sample PHP program 1
// main body:
if(condition)
{
do_stuff_1();
}
else
{
do_stuff_2();
}
// functions
function do_stuff_1()
{
global variables...
lots of code accesing global variables...
}
function do_stuff_2()
{
AGAIN global variables...
lots of code accesing global variables...
}
[/COLOR]
So, I use to opt for this ugly solution:
// sample PHP program 2
// main body:
if(condition)
{
// stuff 1
lots of code accesing global variables...
}
else
{
// stuff 2
lots of code accesing global variables...
}
[/COLOR]
And this way uses to render really big if - elses, difficult to find the end of the brackets, difficult to modularize, etc.
Any ideas on a nice way to do this things (besides not using global vars)?