[wp-trac] [WordPress Trac] #30566: Fix "Trying to get property of non-object" notice when calling get_blogaddress_by_id() with an invalid id.

WordPress Trac noreply at wordpress.org
Mon Dec 1 22:02:44 UTC 2014


#30566: Fix "Trying to get property of non-object" notice when calling
get_blogaddress_by_id() with an invalid id.
--------------------------------+------------------------------
 Reporter:  nerrad              |       Owner:
     Type:  defect (bug)        |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Networks and Sites  |     Version:  trunk
 Severity:  normal              |  Resolution:
 Keywords:                      |     Focuses:  multisite
--------------------------------+------------------------------

Comment (by johnjamesjacoby):

 Seems fine enough as a small improvement.

 ----

 Thinking out loud:

 * In this case, we can trust the results of `get_blog_details()` as it
 either returns `false` or an object which will always have both the
 `domain` and `path` variables set. But, because plugins are forced to fill
 in many multisite/network/mapping gaps, the possibility of an unexpected
 cache value is higher than usual.
 * We could set a default `0` value for the `$blog_id` parameter to
 suppress another possible & similar notice, but other functions like
 `get_id_from_blogname()` would need similar scrutinization.
 * We could check the object more specifically, too:
 {{{
 return ( isset( $bloginfo->domain ) && isset( $bloginfo->path ) ) ? ... :
 '';
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30566#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list