[wp-trac] [WordPress Trac] #63975: wp_delete_auto_drafts passes post ID as string instead of as int
WordPress Trac
noreply at wordpress.org
Thu Sep 18 11:33:17 UTC 2025
#63975: wp_delete_auto_drafts passes post ID as string instead of as int
-------------------------------------------------+-------------------------
Reporter: kkmuffme | Owner: kkmuffme
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Awaiting
| Review
Component: Posts, Post Types | Version: 3.4
Severity: trivial | Resolution:
Keywords: has-patch changes-requested needs- | Focuses:
test-info |
-------------------------------------------------+-------------------------
Changes (by SirLouen):
* keywords: has-patch changes-requested reporter-feedback needs-test-info
=> has-patch changes-requested needs-test-info
Comment:
I knew you were going to answer something like this and then put a
reference to php-src.
I'm unable to reproduce this Fatal error with the code you provided.
{{{
<?php
/*
Plugin Name: Testing
*/
function foo( $post_id ) {
bar( $post_id );
}
function bar( int $post_id ): void {
var_dump( 'bar' );
}
function maybe_delete_post() {
if ( isset( $_GET['foo'] ) && $_GET['foo'] === 'bar' ) {
add_action( 'before_delete_post', 'foo' );
wp_delete_post( '12', true );
}
}
add_action( 'init', 'maybe_delete_post' );
}}}
You have to understand one important thing. Even if I were able to
reproduce the example you provided, it is impossible in real-life
scenarios. Basically these are those edge cases that are great for
academic purposes but should never happen. There are zillions of examples
like this in Trac, you can browse for them.
Put it this way: Imagine that instead of just displaying your theoretical
input, you file a ticket like this:
> **Title**: Fatal error when trying to delete a post
> I'm trying to do a plugin and when I add this code:
{{{
<?php
declare(strict_types=1);
function foo( $post_id ) {
bar( $post_id );
}
add_action( 'before_delete_post', 'foo' );
function bar( int $post_id ): void {}
wp_delete_post( '1' );
}}}
> I get a fatal error. I attach a patch to solve this problem
What kind of answers do you think you will receive?
I guarantee you that any single contributor will answer something like:
"''You are not doing this correctly, you should do this and that''". Even
if it's technically PHP correct code, you are doing things in an
unexpected way or just for the sake of making things fail.
I've worked and even reported a couple tickets like this here in WP but I
still believe they are a waste. Nevertheless, I'm not against solving
them, but as Weston commented, not doing them one by one because there are
thousands of confirmed real-life bugs that are not receiving attention,
and resources, unfortunately, are substantially limited.
One of the proposals that was raised during the meeting yesterday was
moving these kinds of tickets to the PHPStan task, which is slowly but
steadily working to solve these just for the sake of correctness.
My best suggestion here: Create a new PR with the same code and link the
new PR to this ticket #63268
And comment here once you have done, to close this ticket.
PS: Remove that `(array)` static cast if you send the PR.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63975#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list