• Full error message: PHP Warning: Cannot use string as array in D:\wwwroot\xaxaxa\wp-content\plugins\wp-optimize\cache\class-wpo-cache-rules.php on line 242

    WP Optimize version: 4.6.0
    WordPress version: 7.0.2

    On the line 240 – 242:

    // delete all archive pages for post.
    $post_date = get_post_time('Y-m-j', false, $post_id);
    list($year, $month, $day) = $post_date;

    Since get_post_type() is return string, int, false ( https://developer.wordpress.org/reference/functions/get_post_time/ ). So, this code should never work even on old or new PHP. Tested with PHP 7.0 with the code below, all returns null.

    list($a, $b, $c) = 'ada baa caa';
    var_dump($a, $b, $c);// null null null

    I have no idea when this error/warning occurs.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support jbgupdraft

    (@jbgupdraft)

    Hi,

    Thanks so much for reporting this! I’ll see if I can reproduce the error on my test sites. On your site, do you have any plugins that are creating custom post types? If so I’ll try to set my site up in a similar way to reproduce the PHP warning.

    Thanks!

    Thread Starter vee

    (@okvee)

    I disabled all plugins except WP-Optimize and that is the result.

    It’s already crystal clear that the PHP code is wrong. You don’t even need to check for other plugins.

    list($year, $month, $day) = $post_date;// where $post_date is string

    This is not impossible to work. Tested since PHP 7.0 to 8.5. I don’t have PHP older than 7.0 nor can’t install it on my PC.

    https://www.php.net/manual/en/function.list.php

    Assign variables as if they were an array

    Only arrays and objects that implement ArrayAccess can be unpacked.

    Plugin Support jbgupdraft

    (@jbgupdraft)

    Hi,

    You’re absolutely right. I haven’t been able to trigger the same warning yet but I do see that the values are being set to NULL. I’ll ask our developers to look into this so that we can improve this in a future release of WP-Optimize.

    Thanks again for bringing this to our attention!

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.