Support » Plugin: Health Check & Troubleshooting » Array to string conversion in class-health-check-site-status.php on line 2014

  • Toengel

    (@toengel)


    Hi,

    I have the following issue in my logs. Please fix it!

    PHP Notice: Array to string conversion in /wp-content/plugins/health-check/includes/class-health-check-site-status.php on line 2014

    Toengel@Alex

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • titsmaker

    (@titsmaker)

    I have the same issue! Any answer from plugin developers?

    titsmaker

    (@titsmaker)

    They used to answer similar question – https://wordpress.org/support/topic/something-not-quite-right-in-class-health-check-site-status-php-on-line-2034/ and they said it is caused by other plugins. But I tried disabling all plugins and I am still getting “array to string conversion” notice although for another place in plugin code, namely
    Notice: Array to string conversion in ***\wp-content\plugins\health-check\includes\class-health-check-debug-data.php on line 1172
    Upon further investigation it seems that this latter notice is thrown every time I enter plugin page with another one:
    Notice: Array to string conversion in ***\wp-includes\formatting.php on line 1115
    These notices are thrown both with all plugins activated and deactivated.
    As for original notice regarding class-health-check-site-status.php I can’t get what is triggering it, but it appears from time to time. Mostly when I visit my dashboard for the first time during the day.

    • This reply was modified 7 months ago by titsmaker.
    • This reply was modified 7 months ago by titsmaker.

    This problem is bad code in their plugin.
    I have found that when you deactivate it and reactivate it you will see these entries in the logs.

    The offending line of code is $test[[‘test’] which is inside an sprintf method. The %s is expecting a STRING value in the statement below:

    			$function = sprintf(
    				'get_test_%s',
    				$test['test']
    			);

    However, $test[test] is an Array object that looks like this:

    [test] => Array (
    [0] => Health_Check_Site_Status Object
     (
      [mysql_min_version_check:Health_Check_Site_Status:private] => 1
      [mysql_rec_version_check:Health_Check_Site_Status:private] => 1
      [is_mariadb] => 1
      [mysql_server_version:Health_Check_Site_Status:private] => 10.3.23-MariaDB-log-cll-lve
      [health_check_mysql_required_version:Health_Check_Site_Status:private] => 5.5
      [health_check_mysql_rec_version:Health_Check_Site_Status:private] => 10.0
     )
    [1] => get_test_timezone_not_utc
    )

    My guess is that they are attempting to print out get_test_timezone_not_utc (or whatever test it is running. However if they attempt to just pull that from the data then this line:
    'get_test_%s',
    would result in get_test_get_test_timezone_not_utc

    So I THINK the fix is to replace

    			$function = sprintf(
    				'get_test_%s',
    				$test['test']
    			);

    with

    			$function = sprintf(
    				'%s',
    				$test['test'][1]
    			);

    But this reveals another code issue at line 2020

    			} else {
    				$results[] = call_user_func( $test['test']);
    			}

    which I attempted to fixed by adding the [1] to get the test name.

    			} else {
    				$results[] = call_user_func( $test['test'][1] );
    			}

    HOWEVER, whoever coded this still has old data model mixed in with the new data model, and there are tests which are NOT arrays, like the rest of the data model.
    eg: ‘loopback_requests’ and ‘dotorg_communication’

    So their code needs some work, because $test[‘test’] has two differing data structures.

    EDIT:
    Here is how I fixed this for each block in my version of their plugin file class-health-check-site-status.php. It gets rid of the debug log errors… God only knows if it fixes their plugin though…

    foreach ( $tests as $test ) {
      if (is_array($test['test'])) {                  
        $function = sprintf(
          '%s',
          $test['test'][1]
        );
      } else {
        $function = sprintf(
          'get_test_%s',
          $test['test']
        );
      }
      if ( method_exists( $this, $function ) && is_callable( array( $this, $function ) ) ) {
        $results[] = call_user_func( array( $this, $function ) );
      } else {
        if (is_array($test['test'])) {                  
          $results[] = call_user_func( $test['test'][1] );
        } else {
          $results[] = call_user_func('get_test_' . $test['test']);
        }
      }
    }
    

    Bad coding in the plugin indeed! Thanks for a solution @itguysconsulting. I see you entered an issue on Github, so I hope it will make it into the plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.