Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

PHP error messages

Print Track


Server software Linux Centos 7
Webserver software Apache/2
PHP version 7.2.17
PHP interface fpm-fcgi
MySQL Server version 5.5.41-MariaDB
PHP-Fusion version 8.00.22

Error    Date    Status
count(): Parameter must be an array or an object that implements Countable Line: 230

Take a look into the file vriendschap.net/public_html/search.php
Error:    count(): Parameter must be an array or an object that implements Countable    Line:    230
File:    vriendschap.net/public_html/search.php    On Page:    /search.php
Date:    april 19 2019 22:54:39    Status:    

Source code (Line: 220 - 240)
220     $c_swords = count($swords); //sizeof($swords)
221     for ($i = 0; $i < $c_swords; $i++) {
222     $count += substr_count(strtolower($text), strtolower($swords[$i]));
223     }
224     return $count;
225    }
227    function search_querylike($field) {
228     global $swords;
229     $querylike = "";
230     $c_swords = count($swords); //sizeof($swords)
231     for ($i = 0; $i < $c_swords; $i++) {
232     $querylike .= $field." LIKE '%".$swords[$i]."%'".($i < $c_swords - 1 ? " ".$_REQUEST['method']." " : "");
233     }
234     return $querylike;
235    }
237    function search_fieldsvar() {
238     $fieldsvar = "(";
239     $numargs = func_num_args();

Investigated the error and found two solutions. Which one should be prefferred?

     $c_swords = count($swords); //sizeof($swords)

Into: (found in first comment, https://stackoverflow.com/questions/48001569/phpmyadmin-count-parameter-must-be-an-array-or-an-object-that-implements-co)
     $c_swords = count((array)$swords); //sizeof($swords)

Or: (found https://stackoverflow.com/questions/53020833/count-parameter-must-be-an-array-or-an-object-that-implements-countable-in-lar)
     $c_swords = !empty($swords); //sizeof($swords)

Please advise.

3 replies

Good find, !empty would be my first choice since it is cleaner and makes most sense procedural style.
Thanks for fixing it.
author Wanabo
forumSuspected Bugs and Errors - 8
replies4 posts
viewed314 times
activeLast updated on 4 months ago
You can view all discussion threads in this forum.
You cannot set up a bounty in this discussion thread.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
Users who participated in discussion: Falk, Wanabo, RobiNN