downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

ReflectionMethod::getDeclaringClass> <ReflectionMethod::export
[edit] Last updated: Sun, 19 May 2013

view this page in

ReflectionMethod::getClosure

(PHP >= 5.4.0)

ReflectionMethod::getClosureReturns a dynamically created closure for the method

Descrição

public Closure ReflectionMethod::getClosure ( string $object )

Aviso

Esta função não está documentada; somente a lista de argumentos está disponível.

Parâmetros

object

Forbidden for static methods, required for other methods.

Valor Retornado

Returns Closure. Returns NULL in case of an error.



add a note add a note User Contributed Notes ReflectionMethod::getClosure - [1 notes]
up
0
Denis Doronin
4 months 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.

 
show source | credits | sitemap | contact | advertising | mirror sites