Skip to content

[zend-controller] fix undefined array key warning for empty route variables - #241

Open
falkenhawk wants to merge 2 commits into
masterfrom
fix-route-empty-variable
Open

falkenhawk wants to merge 2 commits into
masterfrom
fix-route-empty-variable

Conversation

@falkenhawk

@falkenhawk falkenhawk commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

When the path segment of a route variable is empty, Zend_Controller_Router_Route::match() uses the default of the variable instead.
If the variable has no default, it reads an array key that does not exist:

$route = new Zend_Controller_Router_Route('tag/:tag/page/:page', array('page' => 1));
$route->match('tag//page/3');
// Warning: Undefined array key "tag" (a notice on php 7)
// returns array('tag' => null, 'page' => '3')

Double slashes like this come from broken links or from scanners trying out URLs.
Apps that turn warnings into exceptions answer such requests with a 500 error.

Fix

The variable is set to null when it has no default - the value it already got, now without the warning.
The route still matches as before.

Not matching the route at all would arguably be more correct, but it would change which route handles such URLs, so the current behavior is kept.

Ported from a private repository, based on work by @marcing. There, the route no longer matches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant