PHP 5 Recipes pp 437-451 | Cite as

Using Functions


As you can see, PHP 5 not only supports a myriad of ways to clean up and modularize your code, but it also allows you to manipulate your functions in a wide variety of ways. By using functions to ensure that you are never using redundant code in your applications, you cut back on the time you will spend coding and make your code more applicable both for others to use and for you to clean up should the need arise.

PHP 5 supports passing and receiving values by reference as well as by value, and you should always use the defaults if you think the validity of the code calling the function could ever come into question. The ideal way to do things is to evaluate the task at hand and then select the most efficient method for the job. Passing and returning by reference can be an ideal solution for keeping integrity within a variable or group of variables, and passing and return- ing by value is ideal for working with a given data set.

PHP also supports many ways to base your code upon dynamic dealings. By using dynamic functions or variable function calls, you can reduce the processing and preloading time of your script by deciding on the fly what calls are necessary and which function declarations are important. This allows for a wide range of ingenuity and good, clean coding.

All in all, you can make a powerful set of PHP code that much more efficient by proper, smart function use, and the amount of time it will save you in the end is well worth the initial investment.


Global Variable Function Call Dynamic Function Public Function Redundant Code 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Copyright information

© Lee Babin, Nathan A. Good, Frank M. Kromann, Jon Stephens 2005

Personalised recommendations