ADBRITE ads links
You are here: CodeIdol.com > Php > PHP 5 in Practice > Functions
PHP 5 in Practice
| 6. Functions
Functions in PHP are generally like functions in most other programming languages: They identify blocks of code that can be referenced over and over again. Hence, PHP functions have many of the same characteristics as other lang...
|
|
| 6.1. Setting Optional Parameters
When declaring a function, you may have a parameter that you almost always assign to the same value. You occasionally need to use a different value, though, so you cannot just hard-code the value. PHP provides a so...
|
|
| 6.2. Creating Recursive Functions
A recursive function is defined simply as a function that calls itself. (Also falling under the definition would be any group of functions that loop among themselves, such as function A calling function B, which i...
|
|
| 6.3. Calling Functions Using a Function Name Stored in a Variable
It is possible to store the name of a function as a string and then to call the function from this. Why would you ever want to use this? Well it allows for the function name to be p...
|
|
| 6.4. Dynamically Creating a Function (Lambda-Style)
It is possible in PHP to dynamically create a function and store it in a variable. These functions are often referred to as anonymous functions or Lambda-style functions. (This naming scheme come...
|
|
| 6.5. Using an Array of Functions for Processing
The creation of one Lambda function can add great versatility to a script. Now imagine creating a whole array of Lambda functions. Such an array allows for easy, programmatic access to a function. As...
|
|
| 6.6. Passing or Returning a Value by Reference
Normally in PHP all arguments are passed by value. This means that when you pass a variable in as one of the functions parameters, you get a copy of that variable's value. This way, if you change th...
|
|
| 6.7. Using an Arbitrary Number of Parameters
Default parameters can give you an almost arbitrary list of parameters, although there will always be a limit imposed on how many you declare. There are times when it is useful to allow for any number o...
|
|
| 6.8. Requiring a Parameter to Be a Certain Type
PHP 5 has implemented type hinting. Type hinting requires the parameter of your function (or an object's method) to be of a specific type. As of the writing of this book, PHP 5.1 only allows this t...
|
|
You are here: CodeIdol.com > Php > PHP 5 in Practice > Functions
|
|
Related tags
Popular Categories
Unix books and guides
AJAX popular information
C# language guides
Windows books and cookbooks
.......
|
|