From 49819b41bdc50a3545c03ec01f222425a83911cc Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 25 Dec 2024 10:38:35 -0500 Subject: [PATCH] Don't declare $params until it's neededd --- src/SegmentRouter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SegmentRouter.php b/src/SegmentRouter.php index a149d33..5247c68 100644 --- a/src/SegmentRouter.php +++ b/src/SegmentRouter.php @@ -70,9 +70,6 @@ class SegmentRouter implements RouterInterface // node is a reference to our current location in the node tree $node = $this->routes; - // params will hold any dynamic segments we find - $params = []; - // if the URI is just a slash, we can return the handler for the root node if ($uri === '/') { return isset($node[$method]) @@ -80,6 +77,9 @@ class SegmentRouter implements RouterInterface : ['code' => 405, 'handler' => null, 'params' => null]; } + // params will hold any dynamic segments we find + $params = []; + // We'll split up the URI into segments and traverse the node tree foreach (explode('/', trim($uri, '/')) as $segment) { // if there is a node for this segment, move to it