Vasyl Yaremchuk

We should not use a drupal_goto function in our module hooks!

Today one of my colleague nortmas had explained to the young developers one not obvious but extremely important point. In the begin of my career of Drupal developer I often did that kind of mistake.

I would like to share with us his message:

You should not put drupal_goto() into the hooks of our custom module!


Because our hook function is into the queue of the other functions that represent the same hook in the other contributed and custom modules. The order depends on the weight of the module and alphabetic order in the case of equal weights.

In the case if you will put drupal_goto in your hook function code, you will take away the ability to do necessary actions of the modules that located in the back of the hook order queue.

In any case you should avoid drupal_goto() function in your code because it indicated poor codding style like for example goto operator in classic C language.

Thank you, Dmitry for that helpful blog topic!