• Resolved SeppSoft

    (@seppsoft)


    Hi,
    just upgraded my wordpress driven web site(s) to PHP 7, where I use this plugin.

    Some of them didn’t work correctly anymore and the phperror.log showed the following error:

    PHP Fatal error: Uncaught Error: [] operator not supported for strings in D:\xyz\wp-content\plugins\highlight-search-terms\hlst.php:150

    Line 150 looks like this:
    $searches[] = get_search_query();

    you just have to remove the double square brackets after ‘search’
    to
    $searches = get_search_query();

    and everything works fine ??

    Klaus

    BTW: like the plugin, thanks to the author!

    • This topic was modified 8 years, 1 month ago by SeppSoft.
    • This topic was modified 8 years, 1 month ago by SeppSoft.
Viewing 7 replies - 1 through 7 (of 7 total)
  • That’s strange… $searches should be an array there, not a string so I cannot explain that error. Are you using the latest version 1.4.2 of the plugin?

    Thread Starter SeppSoft

    (@seppsoft)

    >Are you using the latest version 1.4.2 of the plugin?

    Yes, I do.

    When searching the Web for this error, it looks like more people are experiencing this error.
    PHP7 seems to be more strict when declaring variables.
    See:
    https://github.com/spotweb/spotweb/issues/243

    Know that my workaround is not “correct” PHP code.
    But the plugin works and the whole web site, too.

    • This reply was modified 8 years, 1 month ago by SeppSoft.

    PHP7 seems to be more strict when declaring variables.

    That is exactly why $searches is declared as an array just a few lines (line 135) above it. So I really see no reason why PHP should consider $searches as a variable and not an array. I must be going crazy :$

    … Oh hang on, I suspect the get_query_var() which should normally return an array can return a(n empty) string (or null?) when it’s empty. I’ll have to test that.

    In the mean time, could you test for me the following replacement for the lines 150-157 ?

    
    $search = get_search_query();
    // prepare js array
    if ( '1' == get_query_var( 'sentence' ) ) {
    	// treat it as a one sentence search, take only the first search term
    	$filtered[] = $search;
    } else {
    	$filtered = self::split_search_terms($search);
    }
     
    Thread Starter SeppSoft

    (@seppsoft)

    No problem.

    That seems to do the trick.
    Highlighting works as expected and there are no entries in the PHP error log anymore ??

    Appreciate your help.

    Klaus

    Great! Thank you very much for your bug report, feedback and help.

    A new version will be released soon. There are other changes in there too so if you find any issues again, do not hesitate to let me know ??

    Thread Starter SeppSoft

    (@seppsoft)

    Thank you, too ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Error after Upgrade to PHP 7’ is closed to new replies.