Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#35346 closed defect (bug) (wontfix)

WP_Term breaks type-hints for stdClass

Reported by: exz's profile exz Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4
Component: Taxonomy Keywords: close
Focuses: Cc:


Since 4.4.0 instances of WP_Term is returned from various function calls in WordPress core. Before the return value(s) were instances of stdClass. #14162

This makes code that type-hints stdClass not work with 4.4.0+, if you for instance have a callback for array_map() that expects a stdClass you will get:

Argument 1 passed to {closure}() must be an instance of stdClass, instance of WP_Term given

This would be easily fixed by just making WP_Term extend stdClass like this:

final class WP_Term extends stdClass { }

I haven't tested if this breaks something else, but would you consider this change, or is it up to the plugin/theme developer to change all code that expects a stdClass to be able to support 4.4.0+?

Change History (4)

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

9 years ago

#2 @johnbillion
9 years ago

  • Keywords close added
  • Version changed from 4.4.1 to 4.4

I don't think it's unreasonable to expect that a stdClass pseudo-object will at some point get upgraded to a proper class, as happened with WP_Termin 4.4 and with WP_User, WP_Post, etc in previous releases.

This makes type hinting stdClass fragile. I think this issue is a wontfix.

#3 @nerrad
9 years ago

I agree with @johnbillion here. In general I don't think client code should be typehinting stdClass because that's really brittle. stdClass is like a placeholder for better things. So I also favor a wontfix for this ticket.

#4 @boonebgorges
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Thanks for the ticket, @exz . The consensus here and in Slack seems to be that type-hinting for stdClass is not something we want to support. Documentation has always noted that an object (not a stdClass) would be returned here.

Note: See TracTickets for help on using tickets.