[wp-trac] [WordPress Trac] #28310: Accessing properties of null returned from get_post()
WordPress Trac
noreply at wordpress.org
Mon May 19 22:28:54 UTC 2014
#28310: Accessing properties of null returned from get_post()
-------------------------------+-----------------------------
Reporter: GaryJ | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: trunk
Severity: normal | Keywords:
Focuses: |
-------------------------------+-----------------------------
`get_the_date()`, `get_the_time()`, `get_post_time()` and
`get_post_modified_time()` all call `get_post()` and then proceed to
assume that what was returned was an object, and not the `null` that it
could have been. When null is returned, Notices are thrown of "Trying to
get property of non-object'.
My use case is unit testing the filter hook of a shortcode function which
would usually get the post date. The unit test doesn't create a post, and
not should it, since the ability for WP to return the right post date is
not being tested. The PHP Notice generated from core however makes the
unit test into a failure, when it would otherwise have passed the filter
aspect of the test just fine.
In real terms, if a post date or time can't be determined, since the post
can't be determined, then returning an empty string must be better than
generating a Notice?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28310>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list