$app->registeredurlparams is not defined

Moving the rest of the function inside the if loop makes sure $app->registeredurlparams is only referred to if actually exists.

This was causing memory leak on 3.2.1 Joomla install over PHP 5.5, performance has increased after the fix.

This is a replacement for #2706 with a better fix, since there was no response from @FriendlyHacker in 2 months. Thank you for your work.