Make WordPress Core

Opened 7 months ago

Closed 7 months ago

#63802 closed defect (bug) (fixed)

Incorrect @return tag in doc comment for get_post_field()

Reported by: marian1's profile marian1 Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.9 Priority: normal
Severity: minor Version:
Component: Posts, Post Types Keywords: has-patch
Focuses: docs Cc:

Description

get_post_field() either returns an empty string or the sanitised post field value via sanitize_post_field().

Although the documented return type is string, the actual return value and type depend on the requested post field. For example, get_post_field('post_parent', $post_id) returns an integer value.

To align the documentation with the actual behaviour, I suggest updating the @return tag to either mixed (as documented for sanitize_post_field()) or specifying the union of all possible return types.

Change History (3)

This ticket was mentioned in PR #9411 on WordPress/wordpress-develop by @rollybueno.


7 months ago
#1

  • Keywords has-patch added

Update get_post_field() docblock to reflect actual return types (int|string|int[]) instead of always string.

Trac ticket: https://core.trac.wordpress.org/ticket/63802

#2 @SergeyBiryukov
7 months ago

  • Milestone changed from Awaiting Review to 6.9

#3 @SergeyBiryukov
7 months ago

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

In 60621:

Docs: Correct @return type for get_post_field().

Follow-up to [6379], [21559], [24490].

Props marian1, rollybueno.
Fixes #63802.

Note: See TracTickets for help on using tickets.