php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #48742 closure vs anonymous functions.
Submitted: 2009-06-30 15:54 UTC Modified: 2009-11-16 13:15 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: teftin at gmail dot com Assigned:
Status: Wont fix Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-06-30 15:54 UTC] teftin at gmail dot com
Description:
------------
documentation states for function.anonymous states:
"Anonymous functions, also known as closures ..."

this sentence might be true in context of (current) php implementation, but it is not true in general, as not all anonymous functions are closures, and closures don't have to be connected to anonymous functions or functions at all.

http://en.wikipedia.org/wiki/Closure_%28computer_science%29

...
The term closure is often mistakenly used to mean anonymous function. This is probably because most languages implementing anonymous functions allow them to form closures and programmers are usually introduced to both concepts at the same time. These are, however, distinct concepts.


Reproduce code:
---------------
---
From manual page: functions.anonymous
---



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-20 19:27 UTC] info at liefcoden dot nl
Actually, this is not a documentation problem, it is an error in the 
actual naming of the implementation. It would have been better to name 
the internal class "Closure" as "Lambda", as this is the "real" name of 
this concept.

Closure is the concept of introducing variables of an outer scope to the 
current scope, and binding them there.

"function ($quantity, $product) use ($tax, &$total) {}"

This would form closure, whilst:

"function ($quantity, $product) {}"

Would not.
 [2009-11-16 13:15 UTC] vrana@php.net
As the class is named Closure then changing the documentation would worsen readability. Look at anonymous functions without "use" as closures without bound variables.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC