Задать вопрос

Чем отличаются замыкания в php от замыканий в js?

чем отличаются замыкания в php от замыканий в js ?
  • Вопрос задан
  • 2510 просмотров
Подписаться 4 Оценить Комментировать
Пригласить эксперта
Ответы на вопрос 1
alexey-m-ukolov
@alexey-m-ukolov Куратор тега PHP
This caused me some confusion a while back when I was still learning what closures were and how to use them, but what is referred to as a closure in PHP isn't the same thing as what they call closures in other languages (E.G. JavaScript).

In JavaScript, a closure can be thought of as a scope, when you define a function, it silently inherits the scope it's defined in, which is called its closure, and it retains that no matter where it's used. It's possible for multiple functions to share the same closure, and they can have access to multiple closures as long as they are within their accessible scope.

In PHP, a closure is a callable class, to which you've bound your parameters manually.

It's a slight distinction but one I feel bears mentioning.
php.net/manual/en/class.closure.php
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы