Home >Backend Development >PHP Tutorial >javascript closure - Is there a difference between closure function and anonymous function in php? What is closure?

javascript closure - Is there a difference between closure function and anonymous function in php? What is closure?

WBOY
WBOYOriginal
2016-07-06 13:53:121025browse

What exactly is a closure? I’ve heard of it in js before, but I feel like I haven’t used this concept much in actual development? It’s just that recently when I was learning Laraval, I discovered that routing configurations all use closure functions (this is what the tutorial says). I don’t understand what this closure means? I think the code is very similar to the anonymous function in js? Thank you for your answers•﹏•

Reply content:

What exactly is a closure? I’ve heard of it in js before, but I feel like I haven’t used this concept much in actual development? It’s just that when I was learning Laraval recently, I discovered that routing configurations all use closure functions (this is what the tutorial says). I don’t understand what this closure means? I think the code is very similar to the anonymous function in js? Thank you for your answers•﹏•

A closure is a free block of code. In most languages, closures basically appear in the form of anonymous functions. In PHP and JS, anonymous functions can be understood as closures. The two are consistent. . Of course, in PHP, there is also a Closure object to operate closures.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn