Core functinality Flashcards
anonymous functions
Anonymous functions are implemented with Closure class. They can be assigned to variables.
The parent scope of a closure is the function in which the closure was declared (not necessarily the function it was called from).
This is automatically bound, when function is declared inside of a Class.
Closure::bindTo - Create and return a new anonymous function with the same body and bound variables as this one, but possibly with a different bound object and a new class scope.
Also exists static anonymous functions. They don’t have $this, and also could no be bound to the object.
arrow functions (7.4+)
Arrow functions support the same features as anonymous functions, except that using variables from the parent scope is always automatic.
Arrow functions use by-value variable binding. A by-value binding means that it is not possible to modify any values from the outer scope. Anonymous functions can be used instead for by-ref bindings.