Reputation: 11
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:\xampp\htdocs\oscommerce\catalog\admin\includes\functions\general.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;
}
Upvotes: 1
Views: 1690
Reputation: 31
I added below code in the file just the line which was giving the error.
if ($cPath_array == null) {
$cPath_array = array();
}
It has resolved my error
Upvotes: 3
Reputation: 19764
You could also use empty()
. It checks if a variable is "falsy".
if (empty($cPath_array)) { }
Instead of
if (sizeof($cPath_array) == 0) { }
Upvotes: 0
Reputation: 1752
count
's behavior changed in Php 7.2.
count() will now yield a warning on invalid countable types passed to the array_or_countable parameter.
Possible causes:
var_dump(count([])); // OK
var_dump(count((object)[])); // Warning
var_dump(count(null)); // Warning
var_dump(count(false)); // Warning
var_dump(count(123)); // Warning
var_dump(count('123')); // Warning
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.
Upvotes: 1