IAmJulianAcosta IAmJulianAcosta - 1 year ago 118
PHP Question

Modify closure in PHP

Is possible to modify (add more code) to a closure in PHP after is passed to a parameter?

function foo () {
bar (
function () {
$a = baz ();
$b = fooBar ();
function bar (Closure $closure) {
$closure // <------ I need to add code to this function.

Answer Source

No, you can not add or modify a closure, but you can create another closure which calls this closure:

public function getClosure() {
    $closure = getOtherClosure();
    return function() use ($closure) {
        //Do other things
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download