What are Anonymous Functions (Closures) and how do they use the use keyword?

Last updated 15 June 2026

  • A closure is an unnamed function (an instance of Closure) assignable to variables or passed as a callback, e.g. to array_map or usort.

  • Closures don't see outer variables automatically: use imports them by value (snapshot at definition), or by reference with & so changes propagate.

  • Arrow functions (fn() =>, PHP 7.4) capture outer variables by value automatically, so they need no use.

  • https://medium.com/@SonuTechWeb/list-of-common-interview-questions-with-answers-for-a-php-developer-a5468d0b8be
  • https://www.geeksforgeeks.org/category/web-technologies/page/304/?type=recent
All PHP interview questions