Opened 13 months ago
Last modified 6 days ago
#20495 new defect (bug)
Update phpDoc to reflect post id or object is valid
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Inline Docs | Version: | 3.3.1 |
| Severity: | trivial | Keywords: | needs-patch |
| Cc: |
Description
Many functions use get_post() and do so by simply passing along one of their own arguments (typically a post ID). Since get_post() accepts either a post ID or a post object, those functions therefore can (and do) also accept either type of value for the argument.
The phpDoc for many of the functions simply indicate a post ID is valid. The attached patch amends the @param doc entry for the relevant arguments to indicate either a post ID or post object is valid. (There are places where get_post() is used but the int arg is otherwise used in the function as an int -- I've skipped those since they don't really accept a post object.)
Attachments (1)
Change History (11)
coffee2code — 13 months ago
You can be a tad more specific and give the actual type of object (a stdClass) instead of just the generic object.
Replacing object with stdClass doesn't help much. If we had a WP_Post class, that would be something else.
Well, it documents that we know we're expecting an object of type stdClass, rather than some object for which we don't know the type.
I agree that a WP_Post class would be useful in terms of type-hinting, even if it only contains public properties and no methods, but that would be a different ticket.
comment:5
coffee2code — 13 months ago
Specifying something more specific than object warrants a separate ticket. Nowhere in WP (other than a few instances in wp-admin/includes/post.php) is stdClass used in the phpDoc to designate a param or return type. The use of "object" is the current convention.
I'm in full agreement in being more specific when we have more WP classes, such as WP_Post.
- Keywords needs-patch added; has-patch removed
- Milestone changed from Future Release to 3.6
comment:10
ryan — 6 days ago
- Milestone changed from 3.6 to Future Release

Aforementioned patch.