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 01 Answer
Reset to default 1As 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";
}
...