Skip to content

Instantly share code, notes, and snippets.

@igor822
Created June 13, 2014 15:01
Show Gist options
  • Save igor822/3489bc1e355ca7c33681 to your computer and use it in GitHub Desktop.
Save igor822/3489bc1e355ca7c33681 to your computer and use it in GitHub Desktop.
Execute a private method in PHP
<?php
class A {
private function teste() {
return 'teste ab';
}
}
$class = new A();
//$class->teste();
$reflactor = new ReflectionClass('A');
$reflactor_method = $reflactor->getMethod('teste');
$reflactor_method->setAccessible(true);
echo $reflactor_method->invoke($class, NULL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment