How to call overridden parent function via call_user_func_array? (2 posts)

  1. tbaggett
    Posted 8 years ago #

    I created a new class that extends the Walker class. In my new class, I've overridden the walk function to add new functionality.

    I initially attempted to call the base-class implementation using this code:

    return parent::walk($elements, $to_depth);

    I received errors stating:

    [29-Nov-2007 00:42:20] PHP Warning: Missing argument 4 for start_el() in /Applications/MAMP/htdocs/tommyb.dev/wp-content/themes/tbplatinum-20/navbar.php on line 80
    [29-Nov-2007 00:42:20] PHP Warning: Missing argument 5 for start_el() in /Applications/MAMP/htdocs/tommyb.dev/wp-content/themes/tbplatinum-20/navbar.php on line 80
    [29-Nov-2007 00:42:20] PHP Warning: extract() [function.extract]: First argument should be an array in /Applications/MAMP/htdocs/tommyb.dev/wp-content/themes/tbplatinum-20/navbar.php on line 82

    So I thought I should call the base class implementation using call_user_func_array. This is what I tried:

    return call_user_func_array(array(&$this, 'parent::walk'), $args);

    The PHP error log reports:

    PHP Warning: call_user_func_array() [function.call-user-func-array]: First argumented is expected to be a valid callback, 'walker_navbar::parent::walk' was given in /Applications/MAMP/htdocs/tommyb.dev/wp-content/themes/tbplatinum-20/navbar.php on line 48

    So, can anyone tell me how to call the Walker::walk function using call_user_func_array?

    Many thanks for any help!

    Tommy Baggett

  2. $parent_class=get_parent_class($this);
    call_user_func_array(array($parent_class, 'walk'), $args);

Topic Closed

This topic has been closed to new replies.

About this Topic