#44697 closed defect (bug) (fixed)
Argument type does not match: user.php
| Reported by: | subrataemfluence | Owned by: | pento |
|---|---|---|---|
| Priority: | normal | Milestone: | 5.1 |
| Component: | Users | Version: | 5.1 |
| Severity: | normal | Keywords: | has-patch needs-refresh |
| Cc: | Focuses: | coding-standards |
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?
#6
@
8 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
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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.