Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP - Why is there a function defined but not called

Options
  • 08-06-2015 4:10pm
    #1
    Registered Users Posts: 4,258 ✭✭✭


    I'm debugging code for a website and I have noticed that there is a particular function defined but I don't see where the function is called.

    I even did a grep on the whole site for the function but the only instance of it is in it definition.

    Here is the function:

    function salesforcedara_menu() {
    $items = array(
    'page callback' => 'salesforcedara_check_download',
    'page arguments' => array(3, 4),
    'access callback' => true,
    'type' => MENU_CALLBACK,
    );
    $items = array(
    'delivery callback' => 'ajax_deliver',
    ) + $items;

    $items = array(
    'page callback' => 'salesforcedara_start_download',
    'page arguments' => array(4,5),
    'access callback' => true,
    'type' => MENU_CALLBACK,
    );

    return $items;
    }


Comments

  • Registered Users Posts: 1,206 ✭✭✭zig


    Maybe whoever wrote it decided not to use the function, or perhaps an update was done to the site and removed the need to call that function.


  • Registered Users Posts: 241 ✭✭fcrossen


    Grep will not help if the function is called as a variable function - http://php.net/manual/en/functions.variable-functions.php

    Better off to add some logging to the function. Even if the function is never called, it might be someday, and removing it could leave you in a world of pain.


  • Registered Users Posts: 2,030 ✭✭✭colm_c


    That looks like a drupal function, which takes the name of the module and puts _menu at the end of it when loading it, e.g. modulename_menu()

    See here:
    https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7

    So in your case it's handling requests to the following url patterns:

    support/download/file/nojs/*

    and

    support/download/file/start-the-download/*/*

    Whether to remove it or not is a different question.


  • Registered Users Posts: 4,258 ✭✭✭swingking


    Just to give you an update on this , I have removed this and moved it to a menu_router table in the MYSQL database which does the same thing.

    The only problem I have now is that both URLs are calling the same function

    I need to have one button call this function with $nodevalue 267 and another button to call the same function with $nodevalue 275. How would I go about doing this ?

    Thanks



    function salesforcedara_page_build(&$page) {

    $nodevalue = '267';
    if (arg(0) == 'support')
    {
    $node = node_load($nodevalue);


    $page = array(
    '#weight' => 25,
    '#markup' => '<div id="dialog-message" title="'.$node->title.'" style="display:none">'.$node->body[LANGUAGE_NONE][0].'</div>',
    '#attached' => array(
    'library' => array(
    array('system', 'drupal.ajax'),
    array('system', 'ui.dialog')
    ),
    'js' => array(
    array('data' => drupal_get_path('module', 'salesforcedara') .'/js/script.js', 'type' => 'file' , 'scope' => 'footer')
    )
    )
    );
    }
    }


Advertisement