Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP - Why is there a function defined but not called

  • 08-06-2015 04:10PM
    #1
    Registered Users, Registered Users 2 Posts: 4,260 ✭✭✭


    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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 2,011 ✭✭✭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, Registered Users 2 Posts: 4,260 ✭✭✭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