WordPress.org

Make WordPress Core

Opened 22 months ago

#18574 new enhancement

Add class_name support to wpdb

Reported by: andy Owned by:
Priority: normal Milestone: Awaiting Review
Component: General Version:
Severity: normal Keywords: has-patch dev-feedback
Cc:

Description

As of PHP 5.0.0, the second parameter to mysql_fetch_object takes a class name which will be instantiated instead of stdClass. This will be handy as we upgrade core objects (see #12267 and #15458). I am using the attached patch on WordPress.com to simplify a lazy process. The effect is similar to what does with WP_User but the code is much simpler.

The attached patch is fully backward-compatible unless you have defined classes named OBJECT, OBJECT_K, ARRAY_A, or ARRAY_N.

It could be improved by supporting the third parameter to mysql_fetch_object, an array of parameters to pass to the constructor. (For instance, you might want to pass $blog_id when constructing a WP_User). Adding this parameter would be perfectly simple if get_row did not already have a third parameter, $y, which is not used in core and should be removed because it invites wasteful queries.

Attachments (1)

18574.diff (2.7 KB) - added by andy 22 months ago.

Download all attachments as: .zip

Change History (1)

andy22 months ago

Note: See TracTickets for help on using tickets.