Missing argument 1 for hashcash_get_hashcash()

Dave Reid - October 11, 2009 - 21:06
Project:Hashcash
Version:6.x-2.2
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

Using latest stable 6.x-2.1 build I noticed this error occasionally in my site's log:

Missing argument 1 for hashcash_get_hashcash() in /home/.katona/davereid20/drupal-6/sites/all/modules/hashcash/hashcash.module on line 70.

I suspect it has something to do with the hook_menu entry because it does not enforce that there must be a argument passed to hashcash_get_hashcash():

function hashcash_menu(){
  ...
  $items['hashcash'] = array(
    'title' => 'Get Hashcash',
    'description' => 'Returns the start part of a hashcash string',
    'page callback' => 'hashcash_get_hashcash',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
  );
  ...
}

function hashcash_get_hashcash($form_id){
...
}

If the $form_id isn't mandatory, then you should add a default value to it like the following:

function hashcash_get_hashcash($form_id = ''){
...
}

If the $form_id parameter must *always* be present, then you should use something more like the following:

function hashcash_menu(){
  ...
  $items['hashcash/%'] = array(
    'title' => 'Get Hashcash',
    'description' => 'Returns the start part of a hashcash string',
    'page callback' => 'hashcash_get_hashcash',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
  );
  ...
}

I'm guessing the latter is probably the preferred option since it doesn't make sense if $form_id is always desired.

#1

sdrycroft - October 12, 2009 - 08:49

Thanks for this David, you're right, the code should be the same as your second example. What concerns me a little more though, is why is the URL http://example.com/hashcash being retrieved? If I change the code, then that will only replace the PHP warning messages with 404 Not found errors, and doesn't fix the underlying problem. Can you possibly check to see on what page the error is being produced, and with what form?

#2

Dave Reid - October 12, 2009 - 14:28

I should have mentioned that it looked like it was accessed directly since there was no referring page and the error said it came from the /hashcash path. I 404 error would be much preferred.

AttachmentSize
601748-hashcash-undefined-formid-D6.patch 874 bytes

#3

Dave Reid - October 12, 2009 - 14:34
Status:active» needs review

#4

sdrycroft - October 12, 2009 - 14:42
Version:6.x-2.1» 6.x-2.2
Status:needs review» fixed

#5

System Message - October 26, 2009 - 14:50
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.