public static function callFunction( $handler , $matched, $method ) 
	{
		if ( $handler ) {	
			if ( is_callable( $handler ) ) {
				$newParams = call_user_func_array( $handler, $matched ) ;
			} else {
		
				/* Check if class exists in the case user is using RESTful pattern  */
		
				if( class_exists( $handler ) ) {
					$instanceOfHandler = new $handler(); // Won't work in case of middleware since we aren't using RESTful in that
				} else {
					print_r('Class or function ' . $handler . ' not found');
					header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
					die();
				}
			}
		} else {
			self::handle404();
		}

		if( isset( $instanceOfHandler ) ) {
			if( method_exists( $instanceOfHandler, $method ) ) {
				try {
					$newParams = call_user_func_array( array( $instanceOfHandler, $method ), $matched );
				} catch ( Exception $exception ){
					$string = str_replace("\n", ' ', var_export($exception, TRUE));
					error_log($string); //Log to error file only if display errors has been declared
					header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
					die();
				} 	
			}
		}
		if( isset( $newParams ) && $newParams ) {
			return $newParams;		
		}
	}
public static function callFunction( $handler , $matched, $method ) 
	{
		if ( $handler ) {	
			if ( is_callable( $handler ) ) {
				$newParams = call_user_func_array( $handler, $matched ) ;
			} else {
		
				/* Check if class exists in the case user is using RESTful pattern  */
		
				if( class_exists( $handler ) ) {
					$instanceOfHandler = new $handler(); // Won't work in case of middleware since we aren't using RESTful in that
				} else {
					print_r('Class or function ' . $handler . ' not found');
					header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
					die();
				}
			}
		} else {
			self::handle404();
		}

		if( isset( $instanceOfHandler ) ) {
			if( method_exists( $instanceOfHandler, $method ) ) {
				try {
					$newParams = call_user_func_array( array( $instanceOfHandler, $method ), $matched );
				} catch ( Exception $exception ){
					$string = str_replace("\n", ' ', var_export($exception, TRUE));
					error_log($string); //Log to error file only if display errors has been declared
					header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
					die();
				} 	
			}
		}
		if( isset( $newParams ) && $newParams ) {
			return $newParams;		
		}
	}
public static function callFunction ( $ handler , $ matched , $ method ) { if ( $ handler ) { if ( is_callable ( $ handler ) ) { $ newParams = call_user_func_array ( $ handler , $ matched ) ; } else { /* Check if class exists in the case user is using RESTful pattern  */ if ( class_exists ( $ handler ) ) { $ instanceOfHandler = new $ handler ( ) ; // Won't work in case of middleware since we aren't using RESTful in that } else { print_r ( 'Class or function ' . $ handler . ' not found' ) ; header ( $ _SERVER [ 'SERVER_PROTOCOL' ] . ' 500 Internal Server Error' , true , 500 ) ; die ( ) ; } } } else { self :: handle404 ( ) ; } if ( isset ( $ instanceOfHandler ) ) { if ( method_exists ( $ instanceOfHandler , $ method ) ) { try { $ newParams = call_user_func_array ( array ( $ instanceOfHandler , $ method ) , $ matched ) ; } catch ( Exception $ exception ) { $ string = str_replace ( "\n" , ' ' , var_export ( $ exception , TRUE ) ) ; error_log ( $ string ) ; //Log to error file only if display errors has been declared header ( $ _SERVER [ 'SERVER_PROTOCOL' ] . ' 500 Internal Server Error' , true , 500 ) ; die ( ) ; } } } if ( isset ( $ newParams ) && $ newParams ) { return $ newParams ; } }
Static function to handle both middlewares' call and main handler's call.

@param array|string $handler Handler that will handle the routes call or middleware
@param array $matched The parameters that we get from the route wildcard
@return array $newParams The parameters return in the case of middleware if you intend to
the wildcards that were originally passed, this newParams will
be next passed to main handler
Static function to handle both middlewares call and main handler s call .