3v4l.org

run code in 300+ PHP versions simultaneously
<?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');

preferences:
25.61 ms | 404 KiB | 5 Q