tntsearch icon indicating copy to clipboard operation
tntsearch copied to clipboard

Notice: Trying to access array offset on value of type bool (after upgrading to php7.4)

Open dirkjf opened this issue 5 years ago • 3 comments

After upgrading to PHP 7.4 I get a:

Notice: Trying to access array offset on value of type bool

on the search method when using:

$tnt = new TNTSearch();
$results = $tnt->search('example string', 100);```

dirkjf avatar Dec 25 '19 22:12 dirkjf

I rolled back PHP to version 7.3.12 to confirm the problem is linked to PHP 7.4. On 7.3.12 everything works as expected.

dirkjf avatar Dec 25 '19 23:12 dirkjf

I also found two kind of errors in PHP 7.4 related to searching in Grav CMS:

  1. TNTSearch Line 401 : Fixed by using ?? Operator
return $docs->fetch(PDO::FETCH_ASSOC)['value'] ?? "";
  1. PorterStemmer line 396 and 416. Fixed by replacing {} with []
// Line 396
return preg_match("#$c{2}$#", $str, $matches) && $matches[0][0] == $matches[0][1];

// Line 416
if (in_array($matches[1][2], ['w', 'x', 'y'])) {
   $return = false;
}

Hope this help.

iambudi avatar Jan 19 '20 00:01 iambudi

Hello,

I am facing same issue in php 7.4. I tried @iambudi 's solution but in TNTSearch.php, there is only 320lines of code, so where to do his changes ?

jatinbphp avatar Jan 18 '23 08:01 jatinbphp