Functions

Zend PHP 7 Certification – Functions – Anonymous Functions

This post covers the Anonymous Functions section of the Functions chapter when studying for the Zend PHP 7 Certification.
Anonymous functions, which are also known as closures, allow the creation of functions which have no specified name. They are most useful as the value of callback parameters, but they have many other uses.
<?php
$arr …

Zend PHP 7 Certification – Functions – Variable Scope

This post covers the Variable Scope section of the Functions chapter when studying for the Zend PHP 7 Certification.
The scope of a variable is the context within which it is defined.
For a simple procedural PHP script with no functions, the variables will be defined in the global scope.
Any functions added that …

Zend PHP 7 Certification – Functions – Type Declarations

This post covers the Type Declarations section of the Functions chapter when studying for the Zend PHP 7 Certification.
You can use type declarations to specify the expected data type of an argument in a function declaration. In PHP 5.5, these were the allowed types introduced.

Class/interface name
self
array
callable

<?php
class …

Zend PHP 7 Certification – Functions – Returns

This post covers the Returns section of the Functions chapter when studying for the Zend PHP 7 Certification.
Return calls within a function end its execution immediately and pass control back to the line from which it was called. Any data type can be returned, and if a return statement is omitted, then NULL is …

Zend PHP 7 Certification – Functions – References

This post covers the References section of the Functions chapter when studying for the Zend PHP 7 Certification.
You can pass a variable by reference to a function so the function can modify the variable.
<?php
function foo(&$var) {
$var++;
}

$a = 5;
foo($a);
echo $a; // Outputs: 6

Zend PHP 7 Certification – Functions – Variables

This post covers the Variables section of the Functions chapter when studying for the Zend PHP 7 Certification.
Variables declared within functions are only visible in that function. Similarly, variables declared outside of functions are visible everywhere outside of functions. In PHP, there is a global scope. Any variable declared outside of any function is …

Zend PHP 7 Certification – Functions – Arguments

This post covers the Arguments section of the Functions chapter when studying for the Zend PHP 7 Certification.
Information may be passed to functions via the argument list, which is a comma-delimited list of expressions.
<?php
function somefunction($arg1, $arg2, $arg3) {
// Do something
}
Arguments are evaluated from left to …