Problem
The spam_comment and spammed_comment action hooks document $comment_id as @param int but $comment->comment_ID is typed as string by PHPStan (WordPress stores all database fields as strings). This causes a type mismatch.
Affected hooks
spam_comment:
https://github.com/apermo/wordpress-develop/blob/trunk/src/wp-includes/comment.php#L1737-L1746
/**
* @param int $comment_id The comment ID.
* @param WP_Comment $comment The comment to be marked as spam.
*/
do_action( 'spam_comment', $comment->comment_ID, $comment );
spammed_comment:
https://github.com/apermo/wordpress-develop/blob/trunk/src/wp-includes/comment.php#L1754-L1763
/**
* @param int $comment_id The comment ID.
* @param WP_Comment $comment The comment marked as spam.
*/
do_action( 'spammed_comment', $comment->comment_ID, $comment );
Root cause
WP_Comment::$comment_ID is declared as string (all WordPress database-backed properties are strings). The @param int $comment_id type in the hook PHPDoc declares the intended semantic type, but passing $comment->comment_ID directly passes a string.
This pattern affects many hooks throughout core. The cleanest fix per WordPress coding convention is to cast to int at the call site.
Fix
- do_action( 'spam_comment', $comment->comment_ID, $comment );
+ do_action( 'spam_comment', (int) $comment->comment_ID, $comment );
- do_action( 'spammed_comment', $comment->comment_ID, $comment );
+ do_action( 'spammed_comment', (int) $comment->comment_ID, $comment );
Problem
The
spam_commentandspammed_commentaction hooks document$comment_idas@param intbut$comment->comment_IDis typed asstringby PHPStan (WordPress stores all database fields as strings). This causes a type mismatch.Affected hooks
spam_comment:https://github.com/apermo/wordpress-develop/blob/trunk/src/wp-includes/comment.php#L1737-L1746
spammed_comment:https://github.com/apermo/wordpress-develop/blob/trunk/src/wp-includes/comment.php#L1754-L1763
Root cause
WP_Comment::$comment_IDis declared asstring(all WordPress database-backed properties are strings). The@param int $comment_idtype in the hook PHPDoc declares the intended semantic type, but passing$comment->comment_IDdirectly passes astring.This pattern affects many hooks throughout core. The cleanest fix per WordPress coding convention is to cast to
intat the call site.Fix