PHP: Lazy-evaluated static variable

I have a function that is called many times that look like this:

function attachImagesToProduct(Product $csProduct) {
    $searchPath = realpath(__DIR__ . "/../images");
    $files = scandir($searchPath);
    $files = array_map(function ($file) use ($searchPath) {
        return $searchPath . "/" . $file;
    }, $files);
    
    // Does stuff
}

However, the biggest performance issue is on the scandir + array_map parts. I need to do these only one time. This is why I wanted to mark $files as static, but because they are not constant expressions I can’t. Is there any way to mark $files as “lazy-evaluated” static, then I can avoid to do this heavy stuff everytimes I call the function ?