Make WordPress Core

Opened 7 years ago

Closed 6 years ago

#43299 closed defect (bug) (fixed)

function paginate_comments_links() results in a Notice instead of returning an array when 'type' is set to 'array'

Reported by: anantajitjg's profile anantajitjg Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.1 Priority: normal
Severity: normal Version: 4.9.4
Component: Comments Keywords: has-patch
Focuses: template Cc:

Description

function paginate_comments_links() produced a Notice ( Array to string conversion in /opt/lampp/htdocs/wordpress/wp-includes/link-template.php on line 2796 ) instead of returning an array when 'type' is set to 'array'. This function does return an array if 'echo' is set to false, which is pretty confusing ( user needs to pass an additional option of 'echo' => false when it is clear that user needs an array ) when used with 'type' => 'array'!!

Expected
paginate_comments_links() when 'type' is set to 'array' must return an array.

Actual
Instead of returning an array, a Notice is produced.

Steps to reproduce
call the function as described below,

<?php
$links = paginate_comments_links( array(
 'type' => 'array'
) );

Note: WP_DEBUG is set to true

Attachments (2)

43299.diff (1.1 KB) - added by anantajitjg 7 years ago.
43299.2.diff (576 bytes) - added by anantajitjg 7 years ago.
alternative solution

Download all attachments as: .zip

Change History (13)

@anantajitjg
7 years ago

#1 @anantajitjg
7 years ago

  • Keywords has-patch added

#2 @SergeyBiryukov
7 years ago

  • Milestone changed from Awaiting Review to 5.0

#3 follow-up: @SergeyBiryukov
7 years ago

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

In 42703:

Comments: Avoid a PHP notice in paginate_comments_links() if type argument is set to array.

The function is a wrapper for paginate_links(), which returns an array if requested.

Props anantajitjg.
Fixes #43299.

#4 in reply to: ↑ 3 @anantajitjg
7 years ago

  • Keywords dev-feedback added

Replying to SergeyBiryukov:

In 42703:

Comments: Avoid a PHP notice in paginate_comments_links() if type argument is set to array.

The function is a wrapper for paginate_links(), which returns an array if requested.

Props anantajitjg.
Fixes #43299.

Hi,
This is a follow-up to above bug. If I use paginate_comments_links() with no options passed it will result in, Notice: Undefined index: type in /opt/lampp/htdocs/wordpress/wp-includes/link-template.php on line 2928 when WP_DEBUG is set to true. That's why I set, 'type' => 'plain' in defaults array. May be a better solution can remove this Notice :)

#5 @anantajitjg
7 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

If I use paginate_comments_links() with no options passed it will result in, Notice: Undefined index: type in /opt/lampp/htdocs/wordpress/wp-includes/link-template.php on line 2928 when WP_DEBUG is set to true.

With reference to #comment:4 I am proposing an alternative solution!

@anantajitjg
7 years ago

alternative solution

This ticket was mentioned in Slack in #core by anantajitjg. View the logs.


7 years ago

#7 @SergeyBiryukov
7 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 42736:

Comments: After [42703], make sure $args['type'] in paginate_comments_links() is always defined.

Props anantajitjg.
Fixes #43299.

#8 @johnbillion
6 years ago

  • Milestone changed from 5.0 to 5.0.1
  • Resolution fixed deleted
  • Status changed from closed to reopened

#9 @pento
6 years ago

  • Milestone changed from 5.0.1 to 5.0.2

#10 @pento
6 years ago

  • Milestone changed from 5.0.2 to 5.0.3

#11 @SergeyBiryukov
6 years ago

  • Keywords dev-feedback removed
  • Milestone changed from 5.0.3 to 5.1
  • Resolution set to fixed
  • Status changed from reopened to closed

Fixed in [42703] and [42736].

Note: See TracTickets for help on using tickets.