Invalid argument supplied for foreach()

  • Author
    Posts
  • #38482

    1.) What I do
    If I run on the shell wp-cli
    ( from https://github.com/sinebridge/wp-cli-about ):
    $ wp-cli about

    2.) What I get:
    Warning: Invalid argument supplied for foreach() in ~/wp-content/themes/parabola/includes/theme-styles.php on line 13

    3.) Inspection of the Line is:
    foreach ($parabolas as $key => $value) { ${"$key"} = $value ;}

    4.) Question:
    What is wrong?

    5.) Information:
    Wordpress version : 4.5.3
    parabola : 1.7.4
    PHP version : 5.5.38

    6.) Side Information
    I do not get this error on any of the other WP installations (about 12 or so).
    However, this is the only one, where I use your beautiful Parabola Plugin.


    Thank you for any help,
    Cruisen

    • This topic was modified 8 years ago by cruisen.
    • This topic was modified 8 years ago by cruisen.
    • This topic was modified 8 years ago by cruisen.
    #38691
    Zed
    Cryout Creations mastermind

    I am not sure how wp-cli works, but it could be that the global namespaces $parabolas (from line 12) is not available at the moment this utility scans/processes the files, triggering the warning.


    If you like our creations, help us share by rating them on WordPress.org.
    Please check the available documentation and search the forums before starting a topic.
    #42223

    Got the same error.

    Try this one:

    `global $parabolas;
    if (is_array($parabolas)) {
    foreach ($parabolas as $key => $value) { ${“$key”} = $value ;}
    }`

    #42267

    Thanks, ronschi, this works perfect for my installed WP too!

    I expect your code will be included in future versions. wp-cli is widely deployed. I saved it as a patch.

    --- wp-content/themes/parabola/includes/theme-styles.php        2017-01-27 13:07:55.627920010 +0100
    +++ wp-content/themes/parabola/includes/theme-styles.php      2017-01-28 05:44:28.000000000 +0100
    @@ -10,7 +10,7 @@
    
     function parabola_register_styles() {
            global $parabolas;
    -       foreach ($parabolas as $key => $value) { ${"$key"} = $value ;}
    +       if (is_array($parabolas)) {foreach ($parabolas as $key => $value) { ${"$key"} = $value ;}}
    
            wp_register_style( 'parabola-style', get_stylesheet_uri(), NULL, _CRYOUT_THEME_VERSION );
    
    
    #42454
    Zed
    Cryout Creations mastermind

    Unfortunately, the previous workaround does solve the warning but doesn’t solve the main problem with the options array not being available resulting in unpredictable results.


    If you like our creations, help us share by rating them on WordPress.org.
    Please check the available documentation and search the forums before starting a topic.
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Invalid argument supplied for foreach()’ is closed to new replies.