Forum Moderators: coopster

Message Too Old, No Replies

the use of functions (call to)

         

Flolondon

3:25 pm on Apr 3, 2006 (gmt 0)

10+ Year Member



How useful are functions in PHP... does one really need to know them..

jatar_k

5:15 pm on Apr 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the benefit of functions is that you don't need to use the same code chunks over and over

if you find chunks of code that are reused multiple times in your site/application then you can move those to a function in another file. You can then include that file in every script that needs to use that code. You then end up with a function call in each other than the same code repeated over and over.

do you need to use them? No
once you get used to them they will make your life much easier though.

grandpa

6:44 pm on Apr 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



does one really need to know them

In my opinion, yes. A PHP programmer should have a working knowledge of functions, and class objects. Many of the day to day PHP commands that you write into a script are really functions (explode, implode, print_r).

As jatar_k pointed out, using functions can make your life better, especially if you find yourself re-using bits of code. Most of my earliest programs did not contain any functions (that I wrote), and now most of the code I write does include at least one user defined function. One I use extensively manipulates string data, removing extra whitespace from the ends, removing unwanted characters from the string, etc. That function is 6 lines of code, placed once within the script. Without using a function I would have re-written those 6 lines every time I needed to sanitize a string.

Flolondon

4:24 pm on Apr 5, 2006 (gmt 0)

10+ Year Member



ok thanks all