Make WordPress Core


Ignore:
Timestamp:
07/06/2026 04:12:52 AM (3 months ago)
Author:
westonruter
Message:

Docs: Add numeric-string types to DB-backed class properties.

Add @phpstan-var numeric-string annotations to string properties which hold integer database values:

  • WP_Comment::$comment_ID
  • WP_Comment::$comment_post_ID
  • WP_Comment::$comment_karma
  • WP_Comment::$comment_parent
  • WP_Comment::$user_id
  • the eight WP_Site properties backed by integer columns of the wp_blogs table
  • the private WP_Network::$blog_id property

Previously the numeric-string nature of such properties was only indicated in the property description:

A numeric string, for compatibility reasons.

Additionally, document the magic WP_Network::$blog_id property, which is exposed via __get() as a numeric string but was missing from the class-level @property tags.

Finally, correct the documented types of three magic properties:

  • WP_Site::$post_count is lazy-loaded via get_option(), so it is a numeric string once read back from the database and false when the option is not set (new sites with no published posts); it holds an integer only when served from the options cache in the same request that updated it.
  • WP_User::$user_status always holds a numeric string coming raw off the users table row.
  • WP_User::$user_level resolves through user metadata as a numeric string (or an empty string when the metadata is absent), holding an integer only after WP_User::update_user_level_from_caps() has assigned one to the instance in the same request.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/12408.
Follow-up to r37657, r37870, r38630, r48941, r62437.

See #44723, #64896, #64898.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-comment.php

    r61789 r62640  
    2323         * @since 4.4.0
    2424         * @var string
     25         * @phpstan-var numeric-string
    2526         */
    2627        public $comment_ID;
    … …  
    3334         * @since 4.4.0
    3435         * @var string
     36         * @phpstan-var numeric-string
    3537         */
    3638        public $comment_post_ID = '0';
    … …  
    99101         * @since 4.4.0
    100102         * @var string
     103         * @phpstan-var numeric-string
    101104         */
    102105        public $comment_karma = '0';
    … …  
    134137         * @since 4.4.0
    135138         * @var string
     139         * @phpstan-var numeric-string
    136140         */
    137141        public $comment_parent = '0';
    … …  
    144148         * @since 4.4.0
    145149         * @var string
     150         * @phpstan-var numeric-string
    146151         */
    147152        public $user_id = '0';
Note: See TracChangeset for help on using the changeset viewer.