WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Illegal string offset 'total_users' (24 posts)

  1. cogmios
    Member
    Posted 2 years ago #

    see http://wordpress.org/support/topic/illegal-string-offset-total-users?replies=5#post-2889483

    Direct after upgrading to 3.4 I noticed Illegal string offset 'total_users' in update.php on line 75.

    On line 55 it requests

    $user_count = get_user_count( );

    I echo this value and it is an integer (2) so not an array

    on line 73 however it requests

    $user_count['total_users'],

    (so an array..... ) this is where it fails on my WP multisite install.

    So im thinking what could be wrong since my get_user_count() does not return an array but just "2" (so an integer)

    (but obviously this should be an array since it has been an array for always)

  2. Where are you getting the error? On the list users page in the network dash or ...?

  3. cogmios
    Member
    Posted 2 years ago #

    not on any of the normal blog admin pages but on all network admin pages.

    I echo "$user_count" and it returns 2

    so the only thing i can think of is that there is somewhere a (new) filter on site_option_user_count that changes the value from an array to an integer.

    so... im downloading (now) the complete site and plugins to my local disk to serach for something that could do that

    im not sure though

  4. cogmios
    Member
    Posted 2 years ago #

    However....

    ms-functions does :

    $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'") );
    	update_site_option( 'user_count', $count );

    and get_site_option in option.php called by get_user_count in ms-function.php all treat $user_count as an integer

    So ... where DOES it get converted to an array so that in update.php it can actually request $user_count['total_users'],

    ?????

    (for non multisite it gets to be an array in count_users in user.php)

  5. cogmios
    Member
    Posted 2 years ago #

  6. I echo "$user_count" and it returns 2

    Yeah, that's where you're losing me ;)

    Where/why/how are you doing that?

    not on any of the normal blog admin pages but on all network admin pages.

    Do you mean on every single network admin page, you get that error?

  7. cogmios
    Member
    Posted 2 years ago #

    a. yes on every single network admin page
    b. open "\wp-includes\update.php
    c. look at line 55 (3.4) it reads "$user_count = get_user_count( );"
    d. so... $user_count is an integer e.g. 2
    e. now look at line 73 it reads "$user_count['total_users']"
    f. how can that be? requesting an array value "total users" from an integer?

  8. I'm ignoring b through f for a reason, so bear with me. :)

    The error:

    Warning: Illegal string offset 'total_users' in /opt/htdocs/html/wp-includes/update.php on line 75

    There's no reason for you to be mucking around in core, and since WP works just fine, no errors, for pretty much everyone else with this, it's something you 'did' :)

    The update.php file is for "Check WordPress version against the newest version." You can really totally ignore that. I know that's what the error says, it's not what it means.

    So. Manually reinstall 3.4 before we go anywhere else.

  9. cogmios
    Member
    Posted 2 years ago #

    "no errors, for pretty much everyone else with this,"

    are you sure about that?
    What happens when you turn "show errors" on with

    ini_set('display_errors',1);
    error_reporting(E_ALL & ~E_STRICT);

    ? Do you now see it?

  10. Nope.

    But if that was the only way you were able to produce those errors, we have a new track to run down.

    What version of PHP are you using? (5.3.13 for me right now, soon to be .14)

  11. cogmios
    Member
    Posted 2 years ago #

    5.4.3. ... ah... you want me to upgrade to 5.4.4. ? Let me try that. Im also creating a second (clean) multisite on the same (Amazon Linux) server to test, takes some time.

  12. I don't think that 5.4.4 eould really matter, honestly, but it very well could be a PHP issue.

    Have you done a manual reinstall of WP yet?

  13. cogmios
    Member
    Posted 2 years ago #

    'Have you done a manual reinstall of WP yet? '

    yep i did a svn export http://core.svn.wordpress.org/trunk/ –-force . in the root of the site and the first thing i see after logging in is

    *Warning: Illegal string offset 'total_users' in /opt/htdocs/html/wp-includes/update.php on line 73* :)

    hey... the file was edited its now 2 lines higher up :)

    (and 5.4.4 @ ./configure –prefix=/opt/php –with-config-file-path=P/opt/php/etc –with-config-file-scan-dir=/opt/php/etc/php.d –enable-fpm –with-curl –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-zlib –with-openssl –with-mcrypt –enable-mbstring –enable-mbregex –with-gd –with-jpeg-dir –with-png-dir –with-xmlrpc -disable-cgi)

    p.s. running nginx and phpfpm also

  14. Eric Mann
    Member
    Posted 2 years ago #

    I just checked the logic, and it does look (at least from here) like you've found an issue.

    The call to get_user_count() on a Multisite installation does in fact return an integer. The return of this function is assumed to be an array (stored in $user_count) and is referenced as such farther down in the update script.

    A couple of us are looking in to what exactly changed and whether or not this is actually a bug ...

  15. cogmios
    Member
    Posted 2 years ago #

    Thanks http://wordpress.stackexchange.com/users/46/eamann :)

    for reference: i checked back some versions but it seems to be there for some time, even when it was

    $url = "http://api.wordpress.org/core/version-check/1.6/?version=$wp_version&php=$php_version&locale=$locale&mysql=$mysql_version&local_package=$local_package&blogs=$num_blogs&users={$user_count['total_users']}&multisite_enabled=$multisite_enabled";

    instead. So I would expect that WordPress.org would have noticed on the other end that when during a year all requests from multisite installations would be bad concerning user_count someone would notice....?

    That is why i am / was doubting.

    But if it is really a bug it is good to know that really nothing is done with all that data *GRIN*

  16. http://lists.automattic.com/pipermail/wp-hackers/2012-June/043295.html

    When the variables are set. In multisite, we use get_user_count() (a cached
    array), while in single site, we call count_users() (a direct count).

    Not sure it is a bug, if that's related.

  17. Eric Mann
    Member
    Posted 2 years ago #

    OK, I've dug into things a bit and I think this both is and is not a bug.

    Yes, the code looks strange. If we're on multisite, $user_count is set to an integer. In a standalone installation, it's set to an array.

    The $query variable is then constructed from a set of variables, one being $user_count['total_users']. Logically, this should fail for Multisite, and that's exactly what you're seeing.

    However, and this is a big however, I can't reproduce the warning you're seeing. Even setting WP_DEBUG and forcing E_ALL for error reporting, $user_count['total_users'] returns the integer value and not a warning or error.

    I've tried this on two different Apache systems and an Nginx system. I can't get that error back out of the system, though I can see exactly where it would come up. I'll post a ticket on Trac anyway, but I'm not seeing this as a wide-reaching issue (See #20966).

    A short-term fix for you would be to turn off or lower your PHP warning settings.

  18. cogmios
    Member
    Posted 2 years ago #

    I found out... that if I run in a PHP version < 5.4

    $expected_array_got_string = 'somestring';
    echo $expected_array_got_string['some_key'];

    that it returns "s"

    However starting from PHP version 5.4. it will throw: Warning: Illegal string offset 'some_key'

    :)

    I think that's the reason for the low amount of users seeing it...

    (see also example 2 here: http://php.net/manual/en/function.empty.php )

    SO... to see the warning... simply install PHP version 5.4 or later :)

  19. o6asan
    Member
    Posted 2 years ago #

    Thanks for your infomation, cogmios.

    I know this topic is resolved. But I have the same PHP warning, so, I want to say "Thank you!". I also want to add the next information.

    You wrote:

    However starting from PHP version 5.4. it will throw: Warning: Illegal string offset 'some_key'

    However, PHP version 5.4 also returns "s" by my test.

    When I test the next script, a PHP version < 5.4 returns "0", but PHP version 5.4 returns "1".

    $expected_array_got_string = 'somestring';
    echo empty($expected_array_got_string['some_key']);
  20. cogmios
    Member
    Posted 2 years ago #

    Yeah... it seems we are part of the 0.2% grin

  21. Eric Mann
    Member
    Posted 2 years ago #

    In case you haven't been following along, this has been fixed in Core, so it shouldn't be a problem with the next version:

    https://core.trac.wordpress.org/changeset/21105

  22. Eric Mann
    Member
    Posted 2 years ago #

    The patch was included in 3.4.1. After you upgrade, let me know for sure that it resolved the issue. But you should be golden :-)

  23. cogmios
    Member
    Posted 2 years ago #

    18:31 : illegal offset
    18:31 : You can update to WordPress 3.4.1 automatically or download the package and install it manually: click
    18:32 : message gone

  24. o6asan
    Member
    Posted 2 years ago #

    Today, I updated my site. The message has gone, too.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic