Topic: reports_classes.inc:40: count()
I have this error when users access to report area, the error log said:
reports_classes.inc:40: count(): Parameter must be an array or an object that implements Countable
Anybody has an idea?
Thank you
It's much more fun, when you can discuss your problems with others...
You are not logged in. Please login or register.
FrontAccounting forum → Reporting → reports_classes.inc:40: count()
I have this error when users access to report area, the error log said:
reports_classes.inc:40: count(): Parameter must be an array or an object that implements Countable
Anybody has an idea?
Thank you
I got a solution:
in reports_classes.inc change on line 40.
$class_id = count($this->ar_classes);
to
$class_id = is_array($this->ar_classes) ? count($this->ar_classes) : 0;
What do you think?
This is the result of a change from PHP 7.1 to 7.2, as I understand it. In 7.1 and before, a count(NULL) would return zero. Now it issues an error. Your correction should work fine.
@joe commit this fix on core
A search for the string "= count(" reveals several places in several files:
I checked it and not in all cases have to be made changes.
The bug in report_classes.inc has been fixed and committed.
A fixed copy can be downloaded here.
Joe
Quite a few other pages need the changes even if not all listed in my previous post. Would a generic PHP 7.2 function / class file be created with such overrides so as not to have to makes such changes everywhere?
In my personal experiment, I added this function into ui_globals.inc
function count_array($array){
return (is_array($array)) ? count($array) : 0;
}
and replace in all php files "count(" by "count_array("
At this moment, its working for me.
Let me know if my solution works for all.
@cleal - Your solution is ok to use. If you seek other solution,
function count_array($array){
return ($array) ? count($array) : 0;
}
I mean without is_array
But, if parameter is a string? is_array() is useful to stop that error condition.
@joe: Can we change all such each() constructs using @cleal's function?
Yes maybe a good idea.
Joe
All such PHP 7.x gotchas can be made into a separate php7.php file to be included if a PHP7.x version is in use.
I think, into /includes/ui/ one file named like that. In this add all functions to fix issues of deprecated functions or fix others.
And then, add include into /includes/ui.inc
Line 186 file maintenance_db.inc also needs array check function.
Error raising on Installation Wizard step 5.
I will test a solution with rename_function and override_function.
We will include a new file with specific functions with new behaviors if
version_compare >= 7.2.0
Then we do not need to change anything in the code.
Joe
@joe: Line 186 in admin/db/maintenance_db.inc can be preceded with:
if (!(is_array($db_connections)) $db_connections = array($db_connections);
I see that the functions rename_function and override_function are not part of the standard PHP and therefore can not be used.
I will follow @cleal example and review all the count() calls. Where the check is needed I will use the count_array() instead of count().
Joe
Yes, they are part of the Advanced PHP debugger.
I have now committed a fix, where the count() was replaced with count_array(). It was only needed in 3 files and the count_array() was added at the end in the file /includes/ui/ui_globals.inc.
The files are:
/admin/db/maintenance_db.inc(186): $cnt = max(1, count_array($db_connections));
/reporting/includes/reports_classes.inc(37): $class_id = count_array($this->ar_classes);
/sales/includes/sales_db.inc(371): if (!count_array($trans_no))
and the count_array definition:
/includes/ui/ui_globals.inc(65): function count_array($array)
I have been testing FA all over, but I will ask you who has the PHP 7.2.X installed to download a snapshot of 2.4.4 from the repo here.
There was also a problem with the 2.nd parameter in number_format2 in the file /includes/current_user.inc. We used a float value as an integer parameter. Fixed with intval().
Please help me test this snapshot so we can find more odd count() and other problems.
Thank you in advance.
Joe
There are still some where
/includes/ui/items_cart.inc line 312. Error firing on Modifying Journal Transaction
/includes/ui/contacts_view.inc line 137. Error firing on Add Customer Contact without selecting Contact Category
These files have been committed to stable repo. Just replace the count() with count_array() in both places.
Thanks @notrinos for finding these.
Please continue testing. Thanks in advance.
/Joe
pdf_report.inc lines 344 and 379 may need count_array() also.
And includes/ui/ui_globals.inc has to be included here since function count_array() is defined there.
Search for "count(" in the reporting/includes/pdf_report.inc and we find 15 occurrences that need to be replaced with "count_array("
@joe: can commit this along with the inclusion of includes/ui/ui_globals.inc in it.
FrontAccounting forum → Reporting → reports_classes.inc:40: count()
Powered by PunBB, supported by Informer Technologies, Inc.
Currently installed 4 official extensions. Copyright © 2003–2009 PunBB.