0

I've come across the following lines of code in wp-includes/wp-db.php:

/**
 * Last query made
 *
 * @since 0.71
 * @access private
 * @var array
 */
var $last_query;

/**
 * Results of the last query made
 *
 * @since 0.71
 * @access private
 * @var array|null
 */
var $last_result;

I wonder whether, since variables declared with var are public by default, as can be seen here, whether there is an error in the documentation, and whether var in this code snipped should be changed to private or public.

Thanks.

1

As you can guess from version number this code is ancient. So ancient in fact that var keyword is from PHP 4 and is deprecated in PHP 5 (considered synonym of public for backwards compatibility).

So inline doc hints it is private because back then there was no actual property visibility in PHP language.

So conceptually it probably would have been protected in modern code (then it would probably need getters, because these two properties are highly useful for debug).

Practically however these will eternally be de–facto public, because changing them to private/protected would mean breaking backwards compatibility, which WordPress is dead set against.

  • Thanks. So I guess they should be public for backwards compatibility. – John Sonderson Sep 10 '14 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.