$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>menus - Function issue with Walker_Nav_Menu|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

menus - Function issue with Walker_Nav_Menu

matteradmin8PV0评论
This question already has answers here: Error: Declaration of MyClass::start_lvl() should be compatible with that of Walker_Nav_Menu::start_lvl() (3 answers) Closed 6 years ago.

I am getting this warning after updating to PHP 7.2 can anyone help me resolve it?

Warning: Declaration of foundation_navigation::start_lvl(&$output, $depth) should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth = 0, $args = Array) in /nas/content/staging/arnoldhill/wp-content/themes/arnoldhill/functions.php on line 121

The function is currently written like this

// Add class to navigation sub-menu
class foundation_navigation extends Walker_Nav_Menu {

function start_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth);
    $output .= "\n$indent<ul class=\"flyout\">\n";
}

function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
    $id_field = $this->db_fields['id'];
    if ( !empty( $children_elements[ $element->$id_field ] ) ) {
        $element->classes[] = 'has-flyout';
    }
        Walker_Nav_Menu::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
    }
}

Thanks

Henry

This question already has answers here: Error: Declaration of MyClass::start_lvl() should be compatible with that of Walker_Nav_Menu::start_lvl() (3 answers) Closed 6 years ago.

I am getting this warning after updating to PHP 7.2 can anyone help me resolve it?

Warning: Declaration of foundation_navigation::start_lvl(&$output, $depth) should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth = 0, $args = Array) in /nas/content/staging/arnoldhill/wp-content/themes/arnoldhill/functions.php on line 121

The function is currently written like this

// Add class to navigation sub-menu
class foundation_navigation extends Walker_Nav_Menu {

function start_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth);
    $output .= "\n$indent<ul class=\"flyout\">\n";
}

function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
    $id_field = $this->db_fields['id'];
    if ( !empty( $children_elements[ $element->$id_field ] ) ) {
        $element->classes[] = 'has-flyout';
    }
        Walker_Nav_Menu::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
    }
}

Thanks

Henry

Share Improve this question edited Jan 24, 2019 at 11:55 Pratik Patel 1,1091 gold badge11 silver badges23 bronze badges asked Jan 24, 2019 at 11:22 Henry BagilholeHenry Bagilhole 133 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

As you can see here, the declaration of this function looks like this:

public function start_lvl( &$output, $depth = 0, $args = array() ) {

So in your class it should look the same - it should have 3 params. But in your code it has only 2:

function start_lvl(&$output, $depth) {

Also... You shouldn't change visibility of that function, so it also should be public.

So you should change your code so it looks like this:

...
public function start_lvl( &$output, $depth = 0, $args = array() ) {
    $indent = str_repeat("\t", $depth);
    $output .= "\n$indent<ul class=\"flyout\">\n";
}
...

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far