Access variables from parent scope in anonymous PHP function

Use the use keyword to bind variables into the function’s scope.

function() use ($db) {

Closures may also inherit variables from the parent scope. Any such variables must be declared in the function header [using use].

http://www.php.net/manual/en/functions.anonymous.php

Leave a Comment