WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Tweet Blender] Invalid argument supplied for foreach() in /usr/share/wordpress/wp-content/p (11 posts)

  1. Texiwill
    Member
    Posted 4 years ago #

    Invalid argument supplied for foreach() in /usr/share/wordpress/wp-content/plugins/tweet-blender/lib/lib.php on line 374

    Solution:
    Add as Line 374:
    if (!is_array($tweets)) { $tweets=Array(); }

    http://wordpress.org/extend/plugins/tweet-blender/

  2. kirilln
    Member
    Posted 4 years ago #

    Thanks! Will patch and push out a new build tonight.

  3. kirilln
    Member
    Posted 4 years ago #

    Just pushed out 3.1.6 which includes fix for the issue

  4. kirilln
    Member
    Posted 4 years ago #

    Oh, one quick note is that the error you are seeing is because PHP4 can not iterate over objects using "foreach". The fix I have in place right now only takes care of the error message but caching would not work on PHP4. If you are able to upgrade to PHP5 - please do. If not, stay tuned for another patch where I'll write a custom iterator function.

  5. Texiwill
    Member
    Posted 4 years ago #

    I am using PHP 5 so that is not the real issue. the problem is that the $tweets variable is NOT an array.... I had to add in just before line 374 the following once more.

    if (!is_array($tweets)) { $tweets=Array(); }

    This ensures that 'tweets' is always an array which is what 'foreach' wants to use. BTW, I am using PHP v5.2.9. So it is definitely NOT the v4.0 issue you mentioned. It is the fact that $tweets is NOT an array.

  6. kirilln
    Member
    Posted 4 years ago #

    You are correct - $tweets variable does not hold an array it should be an Object with tweet IDs as properties and data structures as values of these properties. Starting with PHP5 the foreach function allows to iterate over arrays and objects - see http://us3.php.net/manual/en/control-structures.foreach.php and http://us3.php.net/manual/en/language.oop5.iterations.php.

    So, in theory, the type mismatch error should not be there if you are on PHP5. Good to know that you are on 5.2.9 - I'll dig some more into this.

    It would be great if you could provide me the URL of your site so I can check on AJAX calls in real time.

    Btw, the line of code you provided assigns a new EMPTY array to $tweets variable so as a result nothing would be cached. It fixes the error message but does not address the root cause.

  7. Texiwill
    Member
    Posted 4 years ago #

    Yes, I know it assigns empty string to the tweet blender, mainly because I rather NOT have the errors. It was filling up my log....

    I also occasionally see:

    PHP Fatal error: Cannot use object of type WP_Error as array in /usr/share/wordpress/wp-content/plugins/tweet-blender/ws.php on line 112,

    - Edward

  8. Texiwill
    Member
    Posted 4 years ago #

    On latest error:

    The solution could be:

    Change line 112 to read something like the following:
    if (!is_wp_error($result) && $result['response']['code'] == 200) {

    As the $result was not checked if it was an 'error'

  9. kirilln
    Member
    Posted 4 years ago #

    Thanks for info on WP_Error issue. I'll add extra checks.

    Can you post URL of your site? I wanted to see if the whole Object vs. Array issue starts earlier - on the JavaScript side when AJAX request is being formed.

  10. Texiwill
    Member
    Posted 4 years ago #

    http://www.virtualizationpractice.com

    GO to the Left, under the 'Tweets' header of the Tabs.

  11. kirilln
    Member
    Posted 4 years ago #

    I added additional logic in 3.1.7 to avoid the error. Hope this will take care of it:
    if (is_array($tweets) || (is_object($tweets) && !version_compare(PHP_VERSION, '5.0.0', '<'))) {

    Will push out in 2-3 days. I also patched ws.php as you recommended. Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic