PHP – Make reference parameter optional?

Taken from PHP official manual:

NULL can be used as default value, but it can not be passed from outside

<?php

function foo(&$a = NULL) {
    if ($a === NULL) {
        echo "NULL\n";
    } else {
        echo "$a\n";
    }
}

foo(); // "NULL"

foo($uninitialized_var); // "NULL"

$var = "hello world";
foo($var); // "hello world"

foo(5); // Produces an error

foo(NULL); // Produces an error

?>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)