ConFoo Montreal 2026: Call for Papers

Voting

: max(six, one)?
(Example: nine)

The Note You're Voting On

Denis Doronin
12 years 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.

<< Back to user notes page

To Top