Dispatcher for a JSON API without routes I am using this code for a fast JSON API without routes.

Does this code contain any useless parts?  Is the class loader efficient enough? Are there any better options? Is ReflectionMethod slow if used once?

&lt;?php

/*
 * Init stuff
 */

session_start();

define('ROOT', realpath( dirname(__FILE__) ) . '/');
set_include_path(ROOT . 'src/');

spl_autoload_extensions('.php');
spl_autoload_register();

ini_set('error_reporting', E_ALL &amp; ~E_DEPRECATED);
ini_set('display_errors',  1); //To change in prod to 0 &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
ini_set('log_errors',      1);
ini_set('error_log',       ROOT . 'tmp/logs/application.log');

date_default_timezone_set('Europe/Paris');

/*
 * Process stuff
 */

$params      = explode( '/', trim( key($_GET), '/' ) );
$paramsCount = count($params);

if ($paramsCount &gt;= 2) {
  try {
    $controllerMethod = new ReflectionMethod( '\app\controller\\' .
                                                  $params[1], $params[2]
                                                );

    if ($paramsCount - 2 &gt;= $controllerMethod-&gt;getNumberOfRequiredParameters()) {

      \ens\controller\Request::$lang =&amp; $params[0];
      \ens\controller\Request::$data =&amp; $_POST;

      $response = $controllerMethod-&gt;invokeArgs( null, array_splice($params, 3) );

    } else {
      $response = array('status' =&gt; 400);
    }

  } catch (ReflectionException $e) {
    $response = array('status' =&gt; 300);
  }

} else {
  $response = array('status' =&gt; 301);
}

if (!headers_sent()) {
  header('Content-Type: application/json');
}

echo json_encode($response);
IMHO, all the ini_set doesn't belong here, but in the php.ini, unless you can't edit it for some reasons…

If so, it belong in a bootstrap file, as for the constant definitions and the include


  A bootstrap file usually starts by including those libraries that are necessary for the file itself to function correctly. This involves setting general directory and file paths, loading configuration files, etc.


This bootstrap file can also be very useful for many reasons described on the link i provided like:


  […] set up different application statuses such as Development, Production or Testing […]


An other thing:

IMHO, the test if (!headers_sent()) is pretty useless as is.

As you are returning JSON, you need to send this header('Content-Type: application/json'), so, if you can't for any reason, you should raise an error or an exception, not just doing nothing and echoing your JSON as if nothing happened…