I cant decide if it is appropriate to use user defined functions for every single action in a page..or it somehow may slow the work? I can alternatively make different php files instead of functions,,and they will do the same thing depending on values of some variables, but i would like to do it the right way. Maybe making functions is better? how you think?

Recommended Answers

All 4 Replies

If it is simpler (less code) then it is probably better. If you need to do the same thing multiple time using different parameters then a function would seem to be the way to go. Unless there is a lot of complex / extra code in the function to make sense of the input parameters and what you need to do with them (versus customized modules for each type of parm), then it won't have any performance impact.

If it is simpler (less code) then it is probably better. If you need to do the same thing multiple time using different parameters then a function would seem to be the way to go. Unless there is a lot of complex / extra code in the function to make sense of the input parameters and what you need to do with them (versus customized modules for each type of parm), then it won't have any performance impact.

thanks a lot) just one more question. If I need to do the same thing multiple times.. i can also require corresponding php file multiple times.. What do you think..are functions still a better way?

Member Avatar for Zagga

Hi kracko,

If you need to run code multiple times on the same page, then a function would probable be the best approach, you can just call the function when needed. If you need to run the code multiple times on different pages, then the require (or include) approach would serve you better.


Zagga

commented: Excellent! +1

hi kracko,

if you need to run code multiple times on the same page, then a function would probable be the best approach, you can just call the function when needed. If you need to run the code multiple times on different pages, then the require (or include) approach would serve you better.


Zagga

thanks! A lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.