Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#23272 closed defect (bug) (fixed)

Notice on class-wp-walker.php

Reported by: rodrigosprimo's profile rodrigosprimo Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 3.6 Priority: normal
Severity: normal Version: 2.7
Component: Warnings/Notices Keywords: has-patch commit dev-reviewed
Focuses: Cc:

Description

When using the Walker class I get the following notice:

Notice: Undefined offset: 0 in wp-includes/class-wp-walker.php on line 126

//display this element
if ( is_array( $args[0] ) )
    $args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );

If I'm not mistaken, this problem is happening because the code assumes that the $args variable is always a non empty array which is not the case.

I'm attaching the code I used to reproduce the problem and a patch to fix it.

Attachments (2)

class-wp-walker.php.patch (595 bytes) - added by rodrigosprimo 11 years ago.
Patch
walker_example.php (641 bytes) - added by rodrigosprimo 11 years ago.
Code used to reproduce the bug

Download all attachments as: .zip

Change History (6)

@rodrigosprimo
11 years ago

Code used to reproduce the bug

#1 @rmccue
11 years ago

  • Keywords has-patch commit added

Looks good to me.

#2 @SergeyBiryukov
11 years ago

  • Milestone changed from Awaiting Review to 3.6
  • Version changed from trunk to 2.7

Introduced in [9830].

#3 @nacin
11 years ago

  • Keywords dev-reviewed added

Looks good, yes.

#4 @SergeyBiryukov
11 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 23346:

Make sure the array exists before adding an element to it. props rodrigosprimo. fixes #23272.

Note: See TracTickets for help on using tickets.