I install the latest version of OSCommerce framework. in backend Categories/Products error shown like:
Warning: sizeof(): Parameter must be an array or an object that implements Countable in C:xampphtdocsoscommercecatalogadminincludesfunctionsgeneral.php on line 93
I try to use is_array()
and count()
but still not working, below are the code
function tep_get_path($current_category_id = '') {
global $cPath_array;
if ($current_category_id == '') {
$cPath_new = implode('_', $cPath_array);
} else {
if (sizeof($cPath_array) == 0) {
$cPath_new = $current_category_id;
} else {
$cPath_new = '';
$last_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where
categories_id = '" . (int)$cPath_array[(sizeof($cPath_array)-1)] . "'");
$last_category = tep_db_fetch_array($last_category_query);
$current_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where
categories_id = '" . (int)$current_category_id . "'");
$current_category = tep_db_fetch_array($current_category_query);
if ($last_category['parent_id'] == $current_category['parent_id']) {
for ($i = 0, $n = sizeof($cPath_array) - 1; $i < $n; $i++) {
$cPath_new .= '_' . $cPath_array[$i];
}
} else {
for ($i = 0, $n = sizeof($cPath_array); $i < $n; $i++) {
$cPath_new .= '_' . $cPath_array[$i];
}
}
$cPath_new .= '_' . $current_category_id;
if (substr($cPath_new, 0, 1) == '_') {
$cPath_new = substr($cPath_new, 1);
}
}
}
return 'cPath=' . $cPath_new;
}
3
Answers
sizeof is an alias of count.
count
‘s behavior changed in Php 7.2.Possible causes:
Please check the data type of
$cPath_array
using var_dump.$cPath_array
is implemented as array in the code but whats its actual value for which warning is generated.Bad and Temporary solution:
Downgrade your Php version.
I added below code in the file just the line which was giving the error.
It has resolved my error
You could also use
empty()
. It checks if a variable is "falsy".Instead of