[wp-trac] [WordPress Trac] #22883: get_page_uri() can produce PHP Warnings when non-WP_Post object instances are passed

WordPress Trac noreply at wordpress.org
Wed Dec 12 11:57:44 UTC 2012


#22883: get_page_uri() can produce PHP Warnings when non-WP_Post object instances
are passed
-----------------------+--------------------------
 Reporter:  dd32       |       Type:  defect (bug)
   Status:  new        |   Priority:  normal
Milestone:  3.5.1      |  Component:  General
  Version:             |   Severity:  normal
 Keywords:  has-patch  |
-----------------------+--------------------------
 A common PHP Warning being posted on the forums includes the following:
 > Warning: Invalid argument supplied for foreach() in wp-includes/post.php
 on line 3588

 This is being caused by the lazy-loading of the ancestor field, with non-
 WP_Post instances being passed in.

 Although I haven't tracked down how themes are using it, using the
 following code in the loop to simulate a WP_Post object being converted to
 a standard StdClass instance duplicates the issue:
 {{{
 var_dump( get_page_uri( (object)(array)$post ) );
 }}}

 The change to fix this seems like an obvious change to me, so I've not yet
 dug into the reasonings behind themes triggering it.

 I've seen the Warning in the wild in a few places, but an example forum
 thread: http://wordpress.org/support/topic/warning-invalid-argument-
 supplied-for-foreach-in-homeftpublic_htmlwp-incl?

 Patch attached, milestone set for review purposes.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22883>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list