Why is initializing a session variable as a variable in a function header considered an error in PHP?

Initializing a session variable as a variable in a function header is considered an error in PHP because session variables should be accessed using the $_SESSION superglobal array. To solve this issue, you should assign the session variable inside the function body rather than in the function header.

// Incorrect way of initializing a session variable in a function header
function myFunction($sessionVar = $_SESSION['variable']) {
    // Function body
}

// Correct way of initializing a session variable inside the function body
function myFunction() {
    $sessionVar = $_SESSION['variable'];
    // Function body
}