WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 months ago

#18574 closed enhancement (maybelater)

Add class_name support to wpdb

Reported by: andy Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Database Keywords: has-patch dev-feedback
Focuses: 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 3 years ago.

Download all attachments as: .zip

Change History (2)

andy3 years ago

comment:1 nacin3 months ago

  • Component changed from General to Database
  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

This is really clever but I doubt this is truly doable until we have classes for all of our DB rows.

Note: See TracTickets for help on using tickets.