PHP.nl

Closure::call

Closure::call

Binds and calls the closure

mixed **Closure::call** object $newThis mixed $args

Temporarily binds the closure to , and calls it with any given parameters. newThis

newThis The to bind the closure to for the duration of the call. object

argsZero or more parameters, which will be given as parameters to the closure.

Returns the return value of the closure.

Voorbeeld: example

<?php
class Value {
    protected $value;

    public function __construct($value) {
        $this->value = $value;
    }

    public function getValue() {
        return $this->value;
    }
}

$three = new Value(3);
$four = new Value(4);

$closure = function ($delta) { var_dump($this->getValue() + $delta); };
$closure->call($three, 4);
$closure->call($four, 4);
?>
int(7)
int(8)

Documentatie