Walker class: Problems with understanding how walk() method can be called without error

Per comments, it’s called with call_user_func_array, so the 1st 2 elements get assigned to the declared arguments $elements and $max_depth, leaving the third element ($r which is the original $args) to be assigned via array_slice to $args. Eg

function wpse172812( $elements, $max_depth ) {
    $args = array_slice(func_get_args(), 2);
    error_log("elements=$elements, max_depth=$max_depth, args=" . print_r( $args, true ));
    // elements=arg1, max_depth=arg2,
    // args=Array ( [0] => Array ( [menu] => my_id [menu_class] => my_class ) )
}
$args = array( 'arg1', 'arg2', array( 'menu' => 'my_id', 'menu_class' => 'my_class' ) );
call_user_func_array( 'wpse172812', $args );

Leave a Comment