[wp-trac] [WordPress Trac] #52298: Using ID as type string instead of int
WordPress Trac
noreply at wordpress.org
Thu Jan 14 20:10:42 UTC 2021
#52298: Using ID as type string instead of int
-------------------------------+------------------------------
Reporter: malthert | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses:
-------------------------------+------------------------------
Comment (by malthert):
And if you look at the code, you see that there is a typecast happening in
sanitize_post(_field) for the ID field:
{{{
$int_fields = array( 'ID', 'post_parent', 'menu_order' );
if ( in_array( $field, $int_fields ) ) {
$value = (int) $value;
}
}}}
Which confirms, as I stated, there is currently no way to retrieve the
post ID as an int, that does not require typecasting. Which means that
using a string would make infinitely more sense (given the reasons in my
first post)
>Changing the ID to a string instead would be a backward compatibility
break.
It wouldn't, since the specifics of int only matter when using
mathematical operations - these are the reasons when PHP7.4+ will give a
notice.
However post IDs cannot be logically used for any mathematical operations
commonly (there may be some fringe cases, but again these should be
handled by these fringe case owners)
Changing post ID params to string, perhaps with a temporary in between of
string|int would not cause any major compatibility issues.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/52298#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list