PROGRAMMING     CLIMBING

  minte9
reminder




Last update:   18-05-2022

Name

Function name is case-insensitive.
 
/** 
 * Function names are case-insensitive
 * 
 * Having a function name() and adding a new one Name() ...
 * throws a Fatal error: Cannot redeclare Name()
 */

function name() {
    echo "1";
}

if (! function_exists('name')) {
    function Name() {
        echo "2";
    }
}

Name(); // "1"

Return

Return is a language construct, parentheses are not required.
 
/**
 * Return is not a function, it is a language construct.
 * Parantheses are not required and ...
 * it is commmont to leave them out.
 */

function A() {
    return (1);
}
    
function B() {
    return 2; // also, it is faster
}
    
echo A(); // Output: 1
echo B(); // Output: 2

Null

A function returns NULL, if you don't return a value.
 
// The concept of "void" functions does not really apply to PHP

function name() {}

echo (name() === NULL); // 1

Questions     github Function
Function anonymous
        A B C D E F
🔔
1/2