3.1 RC2 – Invalid argument supplied for foreach()
-
I just upgraded to RC2 and I’m getting a huge number of PHP warnings – all telling me:
Invalid argument supplied for foreach() in /webstuff/canalblogs/wp-includes/functions.php on line 3064
line 3064 is
foreach ( $list as $key => $obj ) {
in the wp_list_filter function
-
Hi Steve,
We know what would cause an error like this, but not what piece of code in particular is causing this.
It might be a plugin. Think you could deactivate them? You may also wish to switch to the default theme momentarily.
I’d love to nail down what code in particular is causing this, that way we can prevent this, and to confirm that this wasn’t a regression from 3.0.
At worst, we can run what’s called a backtrace to identify exactly where this is coming from. Actually, we can potentially even start there. Just add this immediately before line 3064:
if ( ! is_array( $list ) ) { echo '<pre>'; var_dump( $list ); var_dump( debug_backtrace() ); die(); }
This should give us a pretty good idea of what is causing this.
Thanks,
NacinI’ve got a back trace:
NULL array(12) { [0]=> array(4) { ["file"]=> string(46) "/webstuff/canalblogs/wp-includes/functions.php" ["line"]=> int(3037) ["function"]=> string(14) "wp_list_filter" ["args"]=> array(3) { [0]=> &NULL [1]=> &array(1) { ["_builtin"]=> bool(false) } [2]=> &string(3) "and" } } [1]=> array(4) { ["file"]=> string(41) "/webstuff/canalblogs/wp-includes/post.php" ["line"]=> int(835) ["function"]=> string(21) "wp_filter_object_list" ["args"]=> array(4) { [0]=> &NULL [1]=> &array(1) { ["_builtin"]=> bool(false) } [2]=> &string(3) "and" [3]=> &string(4) "name" } } [2]=> array(4) { ["file"]=> string(44) "/webstuff/canalblogs/wp-includes/rewrite.php" ["line"]=> int(1367) ["function"]=> string(14) "get_post_types" ["args"]=> array(1) { [0]=> &array(1) { ["_builtin"]=> bool(false) } } } [3]=> array(7) { ["file"]=> string(44) "/webstuff/canalblogs/wp-includes/rewrite.php" ["line"]=> int(1517) ["function"]=> string(22) "generate_rewrite_rules" ["class"]=> string(10) "WP_Rewrite" ["object"]=> object(WP_Rewrite)#263 (24) { ["permalink_structure"]=> string(41) "/blog/%year%/%monthnum%/%day%/%postname%/" ["use_trailing_slashes"]=> bool(true) ["author_base"]=> string(6) "author" ["search_base"]=> string(6) "search" ["comments_base"]=> string(8) "comments" ["pagination_base"]=> string(4) "page" ["feed_base"]=> string(4) "feed" ["comments_feed_structure"]=> NULL ["front"]=> string(6) "/blog/" ["root"]=> string(0) "" ["index"]=> string(9) "index.php" ["matches"]=> string(7) "matches" ["rules"]=> bool(false) ["extra_rules"]=> array(0) { } ["extra_rules_top"]=> array(0) { } ["non_wp_rules"]=> array(0) { } ["extra_permastructs"]=> array(0) { } ["endpoints"]=> array(0) { } ["use_verbose_rules"]=> bool(false) ["use_verbose_page_rules"]=> bool(false) ["rewritecode"]=> array(11) { [0]=> string(6) "%year%" [1]=> string(10) "%monthnum%" [2]=> string(5) "%day%" [3]=> string(6) "%hour%" [4]=> string(8) "%minute%" [5]=> string(8) "%second%" [6]=> string(10) "%postname%" [7]=> string(9) "%post_id%" [8]=> string(8) "%author%" [9]=> string(10) "%pagename%" [10]=> string(8) "%search%" } ["rewritereplace"]=> array(11) { [0]=> string(10) "([0-9]{4})" [1]=> string(12) "([0-9]{1,2})" [2]=> string(12) "([0-9]{1,2})" [3]=> string(12) "([0-9]{1,2})" [4]=> string(12) "([0-9]{1,2})" [5]=> string(12) "([0-9]{1,2})" [6]=> string(7) "([^/]+)" [7]=> string(8) "([0-9]+)" [8]=> string(7) "([^/]+)" [9]=> string(8) "([^/]+?)" [10]=> string(4) "(.+)" } ["queryreplace"]=> array(11) { [0]=> string(5) "year=" [1]=> string(9) "monthnum=" [2]=> string(4) "day=" [3]=> string(5) "hour=" [4]=> string(7) "minute=" [5]=> string(7) "second=" [6]=> string(5) "name=" [7]=> string(2) "p=" [8]=> string(12) "author_name=" [9]=> string(9) "pagename=" [10]=> string(2) "s=" } ["feeds"]=> array(5) { [0]=> string(4) "feed" [1]=> string(3) "rdf" [2]=> string(3) "rss" [3]=> string(4) "rss2" [4]=> string(4) "atom" } } ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> &string(41) "/blog/%year%/%monthnum%/%day%/%postname%/" [1]=> ∫(1) } } [4]=> array(7) { ["file"]=> string(44) "/webstuff/canalblogs/wp-includes/rewrite.php" ["line"]=> int(1589) ["function"]=> string(13) "rewrite_rules" ["class"]=> string(10) "WP_Rewrite" ["object"]=> object(WP_Rewrite)#263 (24) { ["permalink_structure"]=> string(41) "/blog/%year%/%monthnum%/%day%/%postname%/" ["use_trailing_slashes"]=> bool(true) ["author_base"]=> string(6) "author" ["search_base"]=> string(6) "search" ["comments_base"]=> string(8) "comments" ["pagination_base"]=> string(4) "page" ["feed_base"]=> string(4) "feed" ["comments_feed_structure"]=> NULL ["front"]=> string(6) "/blog/" ["root"]=> string(0) "" ["index"]=> string(9) "index.php" ["matches"]=> string(7) "matches" ["rules"]=> bool(false) ["extra_rules"]=> array(0) { } ["extra_rules_top"]=> array(0) { } ["non_wp_rules"]=> array(0) { } ["extra_permastructs"]=> array(0) { } ["endpoints"]=> array(0) { } ["use_verbose_rules"]=> bool(false) ["use_verbose_page_rules"]=> bool(false) ["rewritecode"]=> array(11) { [0]=> string(6) "%year%" [1]=> string(10) "%monthnum%" [2]=> string(5) "%day%" [3]=> string(6) "%hour%" [4]=> string(8) "%minute%" [5]=> string(8) "%second%" [6]=> string(10) "%postname%" [7]=> string(9) "%post_id%" [8]=> string(8) "%author%" [9]=> string(10) "%pagename%" [10]=> string(8) "%search%" } ["rewritereplace"]=> array(11) { [0]=> string(10) "([0-9]{4})" [1]=> string(12) "([0-9]{1,2})" [2]=> string(12) "([0-9]{1,2})" [3]=> string(12) "([0-9]{1,2})" [4]=> string(12) "([0-9]{1,2})" [5]=> string(12) "([0-9]{1,2})" [6]=> string(7) "([^/]+)" [7]=> string(8) "([0-9]+)" [8]=> string(7) "([^/]+)" [9]=> string(8) "([^/]+?)" [10]=> string(4) "(.+)" } ["queryreplace"]=> array(11) { [0]=> string(5) "year=" [1]=> string(9) "monthnum=" [2]=> string(4) "day=" [3]=> string(5) "hour=" [4]=> string(7) "minute=" [5]=> string(7) "second=" [6]=> string(5) "name=" [7]=> string(2) "p=" [8]=> string(12) "author_name=" [9]=> string(9) "pagename=" [10]=> string(2) "s=" } ["feeds"]=> array(5) { [0]=> string(4) "feed" [1]=> string(3) "rdf" [2]=> string(3) "rss" [3]=> string(4) "rss2" [4]=> string(4) "atom" } } ["type"]=> string(2) "->" ["args"]=> array(0) { } } [5]=> array(7) { ["file"]=> string(44) "/webstuff/canalblogs/wp-includes/rewrite.php" ["line"]=> int(1876) ["function"]=> string(16) "wp_rewrite_rules" ["class"]=> string(10) "WP_Rewrite" ["object"]=> object(WP_Rewrite)#263 (24) { ["permalink_structure"]=> string(41) "/blog/%year%/%monthnum%/%day%/%postname%/" ["use_trailing_slashes"]=> bool(true) ["author_base"]=> string(6) "author" ["search_base"]=> string(6) "search" ["comments_base"]=> string(8) "comments" ["pagination_base"]=> string(4) "page" ["feed_base"]=> string(4) "feed" ["comments_feed_structure"]=> NULL ["front"]=> string(6) "/blog/" ["root"]=> string(0) "" ["index"]=> string(9) "index.php" ["matches"]=> string(7) "matches" ["rules"]=> bool(false) ["extra_rules"]=> array(0) { } ["extra_rules_top"]=> array(0) { } ["non_wp_rules"]=> array(0) { } ["extra_permastructs"]=> array(0) { } ["endpoints"]=> array(0) { } ["use_verbose_rules"]=> bool(false) ["use_verbose_page_rules"]=> bool(false) ["rewritecode"]=> array(11) { [0]=> string(6) "%year%" [1]=> string(10) "%monthnum%" [2]=> string(5) "%day%" [3]=> string(6) "%hour%" [4]=> string(8) "%minute%" [5]=> string(8) "%second%" [6]=> string(10) "%postname%" [7]=> string(9) "%post_id%" [8]=> string(8) "%author%" [9]=> string(10) "%pagename%" [10]=> string(8) "%search%" } ["rewritereplace"]=> array(11) { [0]=> string(10) "([0-9]{4})" [1]=> string(12) "([0-9]{1,2})" [2]=> string(12) "([0-9]{1,2})" [3]=> string(12) "([0-9]{1,2})" [4]=> string(12) "([0-9]{1,2})" [5]=> string(12) "([0-9]{1,2})" [6]=> string(7) "([^/]+)" [7]=> string(8) "([0-9]+)" [8]=> string(7) "([^/]+)" [9]=> string(8) "([^/]+?)" [10]=> string(4) "(.+)" } ["queryreplace"]=> array(11) { [0]=> string(5) "year=" [1]=> string(9) "monthnum=" [2]=> string(4) "day=" [3]=> string(5) "hour=" [4]=> string(7) "minute=" [5]=> string(7) "second=" [6]=> string(5) "name=" [7]=> string(2) "p=" [8]=> string(12) "author_name=" [9]=> string(9) "pagename=" [10]=> string(2) "s=" } ["feeds"]=> array(5) { [0]=> string(4) "feed" [1]=> string(3) "rdf" [2]=> string(3) "rss" [3]=> string(4) "rss2" [4]=> string(4) "atom" } } ["type"]=> string(2) "->" ["args"]=> array(0) { } } [6]=> array(7) { ["file"]=> string(65) "/webstuff/canalblogs/wp-content/mu-plugins/global-site-search.php" ["line"]=> int(40) ["function"]=> string(11) "flush_rules" ["class"]=> string(10) "WP_Rewrite" ["object"]=> object(WP_Rewrite)#263 (24) { ["permalink_structure"]=> string(41) "/blog/%year%/%monthnum%/%day%/%postname%/" ["use_trailing_slashes"]=> bool(true) ["author_base"]=> string(6) "author" ["search_base"]=> string(6) "search" ["comments_base"]=> string(8) "comments" ["pagination_base"]=> string(4) "page" ["feed_base"]=> string(4) "feed" ["comments_feed_structure"]=> NULL ["front"]=> string(6) "/blog/" ["root"]=> string(0) "" ["index"]=> string(9) "index.php" ["matches"]=> string(7) "matches" ["rules"]=> bool(false) ["extra_rules"]=> array(0) { } ["extra_rules_top"]=> array(0) { } ["non_wp_rules"]=> array(0) { } ["extra_permastructs"]=> array(0) { } ["endpoints"]=> array(0) { } ["use_verbose_rules"]=> bool(false) ["use_verbose_page_rules"]=> bool(false) ["rewritecode"]=> array(11) { [0]=> string(6) "%year%" [1]=> string(10) "%monthnum%" [2]=> string(5) "%day%" [3]=> string(6) "%hour%" [4]=> string(8) "%minute%" [5]=> string(8) "%second%" [6]=> string(10) "%postname%" [7]=> string(9) "%post_id%" [8]=> string(8) "%author%" [9]=> string(10) "%pagename%" [10]=> string(8) "%search%" } ["rewritereplace"]=> array(11) { [0]=> string(10) "([0-9]{4})" [1]=> string(12) "([0-9]{1,2})" [2]=> string(12) "([0-9]{1,2})" [3]=> string(12) "([0-9]{1,2})" [4]=> string(12) "([0-9]{1,2})" [5]=> string(12) "([0-9]{1,2})" [6]=> string(7) "([^/]+)" [7]=> string(8) "([0-9]+)" [8]=> string(7) "([^/]+)" [9]=> string(8) "([^/]+?)" [10]=> string(4) "(.+)" } ["queryreplace"]=> array(11) { [0]=> string(5) "year=" [1]=> string(9) "monthnum=" [2]=> string(4) "day=" [3]=> string(5) "hour=" [4]=> string(7) "minute=" [5]=> string(7) "second=" [6]=> string(5) "name=" [7]=> string(2) "p=" [8]=> string(12) "author_name=" [9]=> string(9) "pagename=" [10]=> string(2) "s=" } ["feeds"]=> array(5) { [0]=> string(4) "feed" [1]=> string(3) "rdf" [2]=> string(3) "rss" [3]=> string(4) "rss2" [4]=> string(4) "atom" } } ["type"]=> string(2) "->" ["args"]=> array(0) { } } [7]=> array(4) { ["file"]=> string(36) "/webstuff/canalblogs/wp-settings.php" ["line"]=> int(154) ["args"]=> array(1) { [0]=> string(65) "/webstuff/canalblogs/wp-content/mu-plugins/global-site-search.php" } ["function"]=> string(12) "include_once" } [8]=> array(4) { ["file"]=> string(34) "/webstuff/canalblogs/wp-config.php" ["line"]=> int(61) ["args"]=> array(1) { [0]=> string(36) "/webstuff/canalblogs/wp-settings.php" } ["function"]=> string(12) "require_once" } [9]=> array(4) { ["file"]=> string(32) "/webstuff/canalblogs/wp-load.php" ["line"]=> int(30) ["args"]=> array(1) { [0]=> string(34) "/webstuff/canalblogs/wp-config.php" } ["function"]=> string(12) "require_once" } [10]=> array(4) { ["file"]=> string(39) "/webstuff/canalblogs/wp-blog-header.php" ["line"]=> int(12) ["args"]=> array(1) { [0]=> string(32) "/webstuff/canalblogs/wp-load.php" } ["function"]=> string(12) "require_once" } [11]=> array(4) { ["file"]=> string(30) "/webstuff/canalblogs/index.php" ["line"]=> int(17) ["args"]=> array(1) { [0]=> string(39) "/webstuff/canalblogs/wp-blog-header.php" } ["function"]=> string(7) "require" } }
and now I’ll go in and start turning stuff off
It would seem to be a couple of Network Blog plugins – specifically the global-site-search plugin from WPMUDEV causing the problem so I’ll chase it up with the developers.
But the odd thing is that nothing seems to be broken – so is it actually acceptable that that variable is null?
Not sure why, but I think something like that is causing the warnings:
$param = new WP_Rewrite;
Indeed, global-site-search.php is calling WP_Rewrite a bit early, it seems. That’s a bad way of doing things; they should instead wait until init to touch the rewrite engine.
Unfortunately, that code is behind a pay wall, so I can’t help the WPMUDEV guys further unless they wish to reach out. (If you contact them, you can let them know I’m willing to assist.)
Thanks Andrew, hooking it to ‘init’ solves the problem, I will let them know 😉
Ivan – so the new_WP_Rewrites and the flush_rules just need wrapping into an init function?
Correct.
Ivan, blog directory is one of the sources 😉
- The topic ‘3.1 RC2 – Invalid argument supplied for foreach()’ is closed to new replies.