PHP 5.4.36 Released

ReflectionMethod::getClosure

(PHP >= 5.4.0)

ReflectionMethod::getClosureReturns a dynamically created closure for the method

Descrizione

public Closure ReflectionMethod::getClosure ( object $object )

Avviso

Questa funzione, al momento non è documentata; è disponibile soltanto la lista degli argomenti.

Elenco dei parametri

object

Forbidden for static methods, required for other methods.

Valori restituiti

Returns Closure. Returns NULL in case of an error.

add a note add a note

User Contributed Notes 1 note

up
1
Denis Doronin
1 year ago
You can call private methods with getClosure():

<?php

function call_private_method($object, $method, $args = array()) {
   
$reflection = new ReflectionClass(get_class($object));
   
$closure = $reflection->getMethod($method)->getClosure($object);
    return
call_user_func_array($closure, $args);
}

class
Example {

    private
$x = 1, $y = 10;

    private function
sum() {
        print
$this->x + $this->y;
    }

}

call_private_method(new Example(), 'sum');

?>

Output is 11.
To Top