4

This is the code used by someone:

/**
 * @Implement of hook_comment()
 */
function mycaptcha_comment(&$comment, $op) {
  global $user;
  switch ($op) {
    case 'insert':
      if (isset($_SESSION['mycaptcha_ask_key'])) {
        // unset the information
        unset($_SESSION['mycaptcha_ask_key']);
      }
    break;
    case 'validate':
      if ($comment['mycaptcha_ask']) {
        // validate the information
        mycaptcha_ask_form_validate($comment['mycaptcha_ask']);
      }
    break;
  }
}

On the above code, why is he using global $user;? I see he doesn't use $user in his code.

1 Answer 1

3

The code is not really using the global $user variable. Probably, the code was first using it, and that line has been left; it could also be the code using it was moved in mycaptcha_ask_form_validate().

As that line is just a variable declaration, there is no problem in leaving it, even if I generally remove it.

1
  • 1
    Correct, my guess is that the code in mycaptcha_form_validate() used $user but was later extracted in a separate function.
    – Berdir
    Commented Jun 30, 2011 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.