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
    case 'validate':
      if ($comment['mycaptcha_ask']) {
        // validate the information

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

1 Answer 1


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
    Correct, my guess is that the code in mycaptcha_form_validate() used $user but was later extracted in a separate function.
    – Berdir
    Jun 30, 2011 at 5:52

Your Answer

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

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