(09-25-2015, 07:04 AM)kilishan Wrote: (09-25-2015, 06:46 AM)jLinux Wrote: Question though, are you sure this is a closure? I think its actually an anonymous function.
I could be wrong though, thats why im asking, you seem a lot more experienced than I am with PHP.
From what I understand, closures will encapsulate all the variables in the environment around them, while anonymous functions need to be passed variables to have access to them.
I honestly always thought they were the same thing with Closure being the specific class name, while anonymous function was just a "layman's term". A little research shows there is a difference in other languages like Javascript but, in PHP they are the same thing. Whenever you create an anonymous function it creates an instance of the class Closure.
Source: PHP Manual on Closures
Ive always thought a closure is a
type of anonymous function
Quote:Anonymous Function - An Anonymous Function is a function that is defined, and occasionally invoked, without being bound to an identifier. It also has the variable scoping characteristics of a Closure (see below).
Closure - A Closure is a function that captures the current containing scope, then provides access to that scope when the Closure is invoked. The Closure binds non-local variable references to the corresponding variables in scope at the time the Closure is created.
Source:
http://dhorrigan.com/post/29209695084/an...s-closures
From what I'm reading, a closure captures the current scope, and the examples in the first post don't, thats what threw me off.
Granted, the "closures" I'm my example don't capture the entire scope, they pick the ones specified in the
use() variables