Menu system - accepts extra args on path Awhile back, working in Drupal 6, I found an issue in which a valid path, say:


  example.com/real/page


would be served if the following did not exist:


  example.com/real/page/fake-arg


I thought it was occurring only with pages defined through Panels and Views, and managed to implement a rather complex check (run during hook_init()) for whether a panel should really be handling that path, and if not, call drupal_not_found().

However...

I just today realized that this same thing occurs with paths defined in Drupal core, e.g.


  user/7


gets served for


  user/7/blah


(This answer is what tipped me off: https://drupal.stackexchange.com/a/5080/834)

So evidently, this is happening by design (and through no fault of the CTools-related modules that instate pages through hook_menu()).

I haven't fully been able to dig into menu_get_item() to figure out how it's accepting the extra args, but my question is: does anyone know a way to get around this behavior and make these non-existent paths result in 404s?
I don't think you can do that in a general way, this is a behavior that's by design and many modules rely on this, so you would break their optional arguments. In fact, relying on this is currently the only way to support optional arguments without defining a menu router item for every possible combination.

If you want to do it for a specific page callback under your control, you could check if there are any arguments passed to your function with func_get_args() and if so, return a 404.

Note that this "feature" might be removed in 8.x, I've seen it mentioned in an issue.