WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Tweet Blender] Invalid argument supplied for foreach() in /usr/share/wordpress/wp-content/p

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

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thanks! Will patch and push out a new build tonight.

    Just pushed out 3.1.6 which includes fix for the issue

    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.

    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.

    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.

    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

    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’

    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.

    http://www.virtualizationpractice.com

    GO to the Left, under the ‘Tweets’ header of the Tabs.

    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!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: Tweet Blender] Invalid argument supplied for foreach() in /usr/share/wordpress/wp-content/p’ is closed to new replies.