From 4e34002ffeb4834a2fe3cbd1dcd297082044c269 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Wed, 26 Mar 2014 20:33:14 +0000 Subject: [PATCH] REGEX BUG : if a parameter is optionnal in the regex, don't show an error git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1263 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- route.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/route.php b/route.php index 6e1b811..12160b2 100644 --- a/route.php +++ b/route.php @@ -537,6 +537,8 @@ class route // URL === REGEXP ROUTE // Variables are exposed in url/{var1}/{var2} $regex = "#^$route$#U"; + //$regex = str_replace ("?", "\?", $regex); + //$regex = str_replace (".", "\.", $regex); $regex = str_replace ("{", "(?P<", $regex); $regex = str_replace ("}", ">.+)", $regex); unset ($matches); @@ -548,7 +550,12 @@ class route $params = array (); $reflect = new ReflectionFunction ($function); foreach ($reflect->getParameters() as $key=>$val) - $params[] = $matches[$val->name]; + { + if (isset ($matches[$val->name])) + $params[] = $matches[$val->name]; + else + $params[] = null; + } call_user_func_array ($function, $params); exit; }