phpstan-wordpress icon indicating copy to clipboard operation
phpstan-wordpress copied to clipboard

Bad types into WP_Post class

Open FlorientR opened this issue 1 year ago • 4 comments

Hi !

There are two bad copy/paste into WP_Post class :

        /**
         * ID of post author.
         *
         * A numeric string, for compatibility reasons.
         *
         * @since 3.5.0
         * @var string
         */
        public $post_author = 0;
// ...
        /**
         * Cached comment count.
         *
         * A numeric string, for compatibility reasons.
         *
         * @since 3.5.0
         * @var string
         */
        public $comment_count = 0;

For this two properties, the @var should be int

Thanks a lot ! Flo

FlorientR avatar Mar 09 '23 16:03 FlorientR

Hi @FlorientR 👋🏻 Thank you for your report.

WP core stubs are automatically generated. https://github.com/WordPress/wordpress-develop/blob/6.1/src/wp-includes/class-wp-post.php#L32-L40 string is there since 2015. Please open a ticket in WordPress trac.

We have no mechanism to fix individual property types. Although you may invent one! PR-s are welcome 😍

szepeviktor avatar Mar 09 '23 16:03 szepeviktor

These are indeed numeric strings, as mentioned in the inline doc right above the type.

johnbillion avatar Mar 09 '23 16:03 johnbillion

😲

A numeric string, for compatibility reasons.

szepeviktor avatar Mar 09 '23 16:03 szepeviktor

It's just occurred to me that the default value is the incorrect type:

public $post_author = 0;

I'll have a dig around in WordPress core and see if this can be fixed.

johnbillion avatar Apr 07 '23 11:04 johnbillion