In what situations would using reflection in addRoute() lead to complications when working with callback functions in PHP?

Using reflection in addRoute() can lead to complications when working with callback functions in PHP because reflection is slower and more resource-intensive compared to direct function calls. To solve this issue, you can store the callback function directly in the route definition instead of using reflection to retrieve it every time the route is matched.

class Router {
    private $routes = [];

    public function addRoute($path, $callback) {
        $this->routes[$path] = $callback;
    }

    public function matchRoute($path) {
        if (isset($this->routes[$path])) {
            $callback = $this->routes[$path];
            $callback();
        } else {
            echo "Route not found";
        }
    }
}

$router = new Router();

$router->addRoute('/home', function() {
    echo "Welcome to the home page!";
});

$router->matchRoute('/home');