update : 2015.11.03
php.shukuma.com

검색:
 
 
Binds and calls the closure

Closure::call

(PHP 7)

Closure::callBinds and calls the closure

설명

public mixed Closure::call ( object $newthis [, mixed $... ] )

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

인수

newthis

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

...

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

반환값

Returns the return value of the closure.

예제

Example #1 Closure::call() 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($three4);
$closure->call($four4);
?>

위 예제의 출력:

int(7)
int(8)