ZF2-143: When assembling string based on routes and route parameters, an absent optional parameter throws InvalidArgumentException even when there are no child routes of the terminating route


Zend\Mvc\Router\Http\Part::assemble (184) line sets option has_child based on if the route has a name or not, instead of whether the route has children. The has_child option set to true precludes the ability for optional route parameters to be NULL and thus excluded from the assembled route.


CLI issue reproduction script. Assumes its place in a project's bin/ directory.

Recommended patch:

diff --git a/library/Zend/Mvc/Router/Http/Part.php b/library/Zend/Mvc/Router/Http/Part.php index 255569f..8a0cfc5 100644 --- a/library/Zend/Mvc/Router/Http/Part.php +++ b/library/Zend/Mvc/Router/Http/Part.php @@ -181,7 +181,7 @@ class Part extends TreeRouteStack implements Route $this->childRoutes = null; }

  • $options['has_child'] = (isset($options['name']));
  •  $options['has_child'] = ($this->childRoutes !== null);
     $path   = $this->route->assemble($params, $options);
     $params = array_diff_key($params, array_flip($this->route->getAssembledParams()));