How to read a function definition (prototype)Each function in the manual is documented for quick reference. Knowing how to read and understand the text will make learning PHP much easier. Rather than relying on examples or cut/paste, everyone should know how to read function definitions (prototypes). Let's begin:
Function definitions tell us what type of value is returned. Let's use the definition for strlen as our first example:
strlen (PHP 4, PHP 5) strlen -- Get string length Description int strlen ( string $string ) Returns the length of given string.
We could rewrite the above function definition in a generic way:
returned type function name ( parameter type parameter name ) Many functions take on multiple parameters, such as in_array. Its prototype is as follows:
bool in_array ( mixed $needle, array $haystack [, bool $strict = FALSE ] )
What does this mean? in_array() returns a
boolean value, In addition the & (ampersand) symbol prepended to a function parameter allows the parameter to be passed by reference, as seen below:
int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )
In this example, we can see the third optional parameter There are also functions with more complex PHP version information. Take html_entity_decode as an example:
(PHP 4 >= 4.3.0, PHP 5) This means that this function has only been available in a released version since PHP 4.3.0. |