Jump to content

Use variables in functions


Francis_and_Hobbel

Recommended Posts

I have a website in which a function is called hundreds of times. There is a variable in the main program that I need within the function, but it's not there. I could add another argument containing that variable

function_name($a,$b,$required_variable);
instead of
function_name($a,$b);

but then the program would become a lot bigger! So is there a method that doesn't require so much extra data?

Link to comment
Share on other sites

An easy patch is to use the global keyword, but usually this kind of situation indicates a fundamental problem with your software's design and it might be worth redesigning your software to make future maintenance easier.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...