Stric Standard error with WordPress nav walker function

The themeforest support tell me that I have this two errors in a WordPress theme:
this and this.

This is the wp_nav_menu walker function:

Read More
class description_walker extends Walker_Nav_Menu
{

  function start_el(&$output, $item, $depth, $args )
  {
       global $wp_query;
       $indent = ( $depth ) ? str_repeat( "t", $depth ) : '';

       $class_names = $value = '';

       $classes = empty( $item->classes ) ? array() : (array) $item->classes;

       $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
       $class_names = ' class="'. esc_attr( $class_names ) . '"';

       $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';

       $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
       $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
       $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
       $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';

       if($depth != 0)
       {
                 $description = $append = $prepend = "";
       }

        $item_output = $args->before;
        $item_output .= '<a'. $attributes .' class="external">';
        $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID );
        $item_output .= '</a>';
        $item_output .= $args->after;

        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );

                    if ($item->menu_order == 1) {
            $classes[] = 'first';
        }

        }
}

The problem is that my WordPress doesnt show this errors. I have WordPress 3.8.1 and I haveWP_DEBUG` set to true.

The first error seems to fixed changing this line: function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0).
The second error I have change $item_output = $args->before; to $item_output = $args['before']; But this cause an error:

Fatal error: Cannot use object of type stdClass as array in /home/codetoco/public_html/wp-content/themes/quins/functions.php on line 338

Why are they getting an error an me not? How can I fix this errors?

Related posts

Leave a Reply

1 comment

  1. The second error I have change $item_output = $args->before; to
    $item_output = $args[‘before’]; But this cause an error:

    Fatal error: Cannot use object of type stdClass as array in
    /home/codetoco/public_html/wp-content/themes/quins/functions.php on
    line 338

    Its because $args is an object and not an array so you need to use the -> instead of []

    You might also want to check out this to find more about enabling error reporting in PHP. It really helps to enable error reporting during development as it immediately informs you when you do something wrong. But be sure to disable it when you push your code to a live server as this can be a potential cause for leaking information that you don’t want the outside world to know.