#44697 closed defect (bug) (fixed)
Argument type does not match: user.php
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 5.1 | Priority: | normal |
| Severity: | normal | Version: | 5.1 |
| Component: | Users | Keywords: | has-patch needs-refresh |
| Focuses: | coding-standards | Cc: |
Description
File location: wp-includes/user.php
<?php /* * ... * @param int $for_user_id Optional. User ID to set up global data. */ function setup_userdata( $for_user_id = '' ) { ... }
Attachments (2)
Change History (9)
#3
@
8 years ago
I had the same initial feeling but got a kinda confused!
Now, since the default value set for $for_user_id is 0, can this be better idea to rewrite the comparison block like this?
if ( '' == $for_user_id || 0 == $for_user_id ) {
$for_user_id = get_current_user_id();
}
$user = get_userdata( $for_user_id );
This ensures $for_user_id gets the current user id for default values.
And if fails to satisfy the above condition, rest will be executed as tNB: Ire.
And if the default value for $for_user_id is set to 0, do we really need to compare it with an empty string?
#5
@
7 years ago
- Owner set to pento
- Resolution set to fixed
- Status changed from new to closed
In 44603:
#6
@
7 years ago
@pento FYI we usually put the default value last, per https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/#1-functions-class-methods
Note: See
TracTickets for help on using
tickets.
Hi @subrataemfluence, thanks for the ticket!
The existing type is correct,
$for_user_idshould be an integer, not a string.That said, it could use a better default value, i.e.
0instead of an empty string. Given the non-strict check a few lines below, changing it to0should not affect the logic.