PHP Syntax and Semantics - Functions

Functions

PHP has hundreds of base functions and thousands more from extensions. Functions are not first-class functions and can only be referenced by their name prior to PHP version 5.3.0, whereas PHP 5.3.0 introduces closures. User-defined functions can be created at any time and without being prototyped. Functions can be defined inside code blocks, permitting a run-time decision as to whether or not a function should be defined. There is no concept of local functions. Function calls must use parentheses with the exception of zero argument class constructor functions called with the PHP new operator, where parentheses are optional.

An example function definition is the following:

Prior to version 5.3, PHP only supports quasi-anonymous functions through the create_function function. These are not true anonymous functions because anonymous functions are nameless but functions can only be referenced by name in PHP. As of version 5.3, PHP supports true anonymous functions.

Function calls may be made via variables, where the value of a variable contains the name of the function to call. This is illustrated in the following example:

PHP does not support named parameters or parameter skipping. Some core PHP developers have publicly expressed disappointment with this decision. Others have suggested workarounds for this limitation.

Read more about this topic:  PHP Syntax And Semantics

Famous quotes containing the word functions:

    If photography is allowed to stand in for art in some of its functions it will soon supplant or corrupt it completely thanks to the natural support it will find in the stupidity of the multitude. It must return to its real task, which is to be the servant of the sciences and the arts, but the very humble servant, like printing and shorthand which have neither created nor supplanted literature.
    Charles Baudelaire (1821–1867)

    When Western people train the mind, the focus is generally on the left hemisphere of the cortex, which is the portion of the brain that is concerned with words and numbers. We enhance the logical, bounded, linear functions of the mind. In the East, exercises of this sort are for the purpose of getting in tune with the unconscious—to get rid of boundaries, not to create them.
    Edward T. Hall (b. 1914)

    Let us stop being afraid. Of our own thoughts, our own minds. Of madness, our own or others’. Stop being afraid of the mind itself, its astonishing functions and fandangos, its complications and simplifications, the wonderful operation of its machinery—more wonderful because it is not machinery at all or predictable.
    Kate Millett (b. 1934)