WordPress Testing – Efficient way of using Array

Following question arises we had a testing session in wordpress core,

Which is the efficient way of using the wpdb class objects outputs in wordpress?

Read More

Example,
Getting wp users table name,

$wpdb->tables('all')['users']

(or)

$wpdb->users

In both of the above ways we can get the users table name, Why developers are preferring $wpdb->users more than $wpdb->tables('all')['users'],

Is there any specific reason in the efficiency and how can we test this out?

Related posts

Leave a Reply

1 comment

  1. I’m not sure how this specific code works, but I may assume that it is using a magic method __get in your wpdb object class.

    According to this benchmark, using the magic methods is slower than using the standard methods ; magic methods benchmarks. Therefore, it looks like in some cases, as the one you describe, it can be better in terms of code readability / maintenance to use a magic method.

    I’m no expert in data structure and caching of object structures behind, but there might be some advantages to use the object properties directly instead of magic methods when it comes to opcaching as well, but I’m really not sure about this (a bit as using traditional methods instead of closures).