- is_callable: documentation ( source)
<?php
class ApiController
{
/*
*
* Public methods meant to be exposed...
*
*/
protected function protectedMethod()
{
echo "This should be protected!";
}
public function handle($method)
{
if (!is_callable(array($this, $method)))
{
die("Not callable!");
}
$refMethod = new ReflectionMethod($this, $method);
$refMethod->invoke($this); // No visibility check
}
}
// Simulate a web request
$api = new ApiController();
$api->handle('protectedMethod');