How does the resolution of static declarations in compile-time impact PHP functions?

When using static declarations in PHP functions, the resolution of these declarations occurs at compile-time. This means that if a static variable is initialized with a function call, the function will only be called once during compilation and not every time the function is executed. To solve this issue and ensure that the function is called every time the function is executed, you can initialize the static variable to null and then assign the function call inside the function body.

function myFunction() {
    static $cachedValue = null;
    
    if ($cachedValue === null) {
        $cachedValue = expensiveFunctionCall();
    }
    
    // rest of the function code
}

function expensiveFunctionCall() {
    // perform expensive operation
}