Object Oriented PHP Url Router I just finished rewriting my Router class. Any input would be much appreciated.

The class routes URLs based on a site.com/class/method/param/param/etc syntax.

One thing I've done differently is created a mechanism for basic templates to be loaded directly without the need for a controller. I often find pages such as /about/ do not require additional methodology, and setting up really basic controllers just seems like a waste of time. Therefore, I have created a check for templates such as _about.php in the views folder, with the underscore denoting that it can be loaded directly.

The class also currently assumes an error class or template.

class Router{

    public static function getPath($uri = null){
        // set default uri
        $uri = is_null($uri) ? $_SERVER['REQUEST_URI'] : $uri;

        // remove possible query string
        $uri = preg_replace('/\?(.*)/', '', $uri);

        return explode('/',trim($uri,'/'));
    }

    public static function getQuery($uri = null){

        // set default uri
        $uri = is_null($uri) ? $_SERVER['REQUEST_URI'] : $uri;

        // get query string
        $query = substr($uri, strpos($uri,'?') + 1);

        // parse into array
        $q = array();
        parse_str($query,$q);

        return $q;
    }

    public static function follow($uri = null){

        $path = self::getPath($uri);

        // get controller and method, or set defaults of root and index
        $controller = ($path[0] == "") ? 'root' : $path[0];
        $method = ((count($path) &gt; 1) &amp;&amp; ($path[1] != "")) ? $path[1] : null;

        // see if controller is a static page, only possible if no method specified
        if(is_null($method) &amp;&amp; file_exists(APPLICATION_DIR . '/views/_' . $controller . '.php')){
            include APPLICATION_DIR . '/views/_' . $controller . '.php';
        }
        else if(file_exists(APPLICATION_DIR . '/controllers/' . $controller . '.php')){ // see if controller exists
            // load controller class
            include_once APPLICATION_DIR . '/controllers/' . $controller . '.php';

            // if method is empty or doesn't exist, it defaults to "index"

            if(is_null($method) || !method_exists($controller,$method)) {
                $method = "index";
            }

            if(method_exists($controller, $method)){
                $c = new $controller();
                $c-&gt;$method();
            }
            else{
                self::follow('e404');
            }
        }
        else{
            self::follow('e404');
        }

    }

}
This is not OOP.

Observe how your class contains only static functions.  There are no class properties.  This can be written equivalently:

namespace Router;

function getPath($uri = null){
    // Same implementation (I have just cut it out for readability).
}

function getQuery($uri = null){
    // Same implementation.
}

function follow($uri = null){
    // Same implementation.
}


Usage from anywhere can be compared (First your code):

Router::getPath($uri);
Router::getQuery($uri);
Router::follow($uri);


Then the equivalent:

Router\getPath($uri);
Router\getQuery($uri);
Router\follow($uri);


Note how no object is required to be used (that is a good hint that its not OO).

The following question would be worth reading:

User class design

I have an answer to that question which covers in more detail some of the problems with using static in OOP.