In this post I will explain the different types of function which comes into play while working with PHP.
Below are the List of PHP function types:
Now let’s start each type in detail:
This function may be defined using syntax such as following:
Function names follow the same rules as other labels in PHP. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.
You can see the Function naming rules at here.
Function needs to be defined before they are referenced, except when function is conditionally defined.
When a function is defined in conditional manner such as below example, It must be processed prior to being called.
This is same as user defined function but it will return some values based on passed argument using return statement. Check below example:
PHP support the concept of the variable function. This means that if a variable name has parentheses appended to it, PHP will look for a function with the same name as the whatever variable evaluate to, and will attempt to execute it. This can be used to implement callbacks, function tables, etc.
PHP comes with some standard functions and constructors. There also some functions which require to enable PHP extension, otherwise fata “undefined function” error will appear.
Anonymous functions, also known as closures, allow creation of functions which have no specified name.
Closures can also be used as the values of variables; PHP automatically converts such expressions into instances of the Closure internal class. Assigning a closure to a variable uses the same syntax as any other assignment, including the trailing semicolon:
Hope you find this information useful for you. Waiting for your responses.
Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.
View all posts by: Avinash