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.
Wanabo

PHP error messages

by Wanabo, Last updated on 29 days ago in Suspected Bugs and Errors - 8

Quote

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
public_html/search.php
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
Details
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    }
226    
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    }
236    
237    function search_fieldsvar() {
238     $fieldsvar = "(";
239     $numargs = func_num_args();
240


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

Rewrite:
     $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.
www.probemyip.com/probe-my-ip-80x15.png

pHp-Fusion.Asia & pHp-Fusion.Fr & pHp-Fusion.Cn are available for a localized support community. Send PB for info.
Good find, !empty would be my first choice since it is cleaner and makes most sense procedural style.
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Please read and comply with the Code of Conduct

(¯`·._.·(¯`°·._.·°º*[ Project Manager ]*º°·._.·°´¯)·._.·´¯)
https://github.com/php-fusion/PHP-Fusion/commit/2f9cbfa82f9cc716342911c6d9462e9bffcb7714
PHP-Fusion Development Manager
Web Designer/Developer: GitHub
Thanks for fixing it.
www.probemyip.com/probe-my-ip-80x15.png
pHp-Fusion.Asia & pHp-Fusion.Fr & pHp-Fusion.Cn are available for a localized support community. Send PB for info.
You can view all discussion threads in this forum.
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.
Users who participated in discussion: Falk, Wanabo, RobiNN