In short
No, there is no special name
Some more explanations
Since you capture the variable by value and not by reference, and since PHP uses early binding, this closure will indeed return the value of $contents at the time the closure was created. You could as well just return a constant.
But this does not matter. All the interest of a closure is to define a behavior on the fly, that can be executed as a normal function, if needed with arguments. Whether the value is constant or a very complex calculation only matters to the context that defined the closure. The context that uses the closure doesn’t know what the closure will return.
There is hence no reason to give a name to this particular form of closures.
Would you look for a name anyway:
- a closure defines an unnamed function. So for categorizing closures according to specific behavior the same terminology should bed used as for normal functions.
- a function that returns a constant value is called a constant function constant function in mathematics. So a constant closure (or constant lambda expression in other languages) could be candidate.
- unfortunately, in PHP the
constantfunction is already taken, so that this might create some ambiguities. - furthermore it’s not the closure itself that is constant, but the value it returns.
All this makes a closure returning a constant the best candidate. Of course this is not very original, and it’s certainly not among the most frequent use of closures in the real world. Maybe this is why nobody really bothered to find a name for it ;-)