Fatal error: Call to undefined function arg()

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


26 points

I get Fatal error: Call to undefined function arg() in my hook_init() in my custom module when checking for arg(1). This works well for authenticated user, but fails for logged out users. Any help?



7 points

Try disabling cache and/or in your custom code check for arg() function as follows:

<?php
  
if (function_exists('arg') && arg(0) == 'node' && (is_numeric(arg(1)) || is_numeric(arg(2)))) {
?>

Anonymous's picture
Created by Anonymous

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.