为了账号安全,请及时绑定邮箱和手机立即绑定

如何解决Oscommerce,警告:sizeof():参数必须是数组或实现Countable的对象

如何解决Oscommerce,警告:sizeof():参数必须是数组或实现Countable的对象

PHP
炎炎设计 2023-07-30 13:14:53
我安装了最新版本的 OSCommerce 框架。在后端类别/产品错误中显示如下:警告:sizeof():参数必须是在 C:\xampp\htdocs\oscommerce\catalog\admin\includes\functions\general.php 第 93 行中实现 Countable 的数组或对象我尝试使用is_array()但count()仍然无法正常工作,下面是代码   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 回答

?
慕丝7291255

TA贡献1859条经验 获得超6个赞

我在文件中添加了以下代码,只是给出错误的行。

if ($cPath_array == null) {
    $cPath_array = array();
}

它解决了我的错误


查看完整回答
反对 回复 2023-07-30
?
精慕HU

TA贡献1845条经验 获得超8个赞

sizeof是count的别名。

count的行为在 PHP 7.2 中发生了变化。

count() 现在将对传递给 array_or_countable 参数的无效可数类型发出警告。

可能的原因:

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

$cPath_array请检查使用var_dump的数据类型。$cPath_array在代码中作为数组实现,但生成警告的实际值是多少。

糟糕的临时解决方案: 降级你的 PHP 版本。


查看完整回答
反对 回复 2023-07-30
?
慕工程0101907

TA贡献1887条经验 获得超5个赞

您也可以使用empty(). 它检查变量是否为“假”。

if (empty($cPath_array)) { }

代替

if (sizeof($cPath_array) == 0) { }


查看完整回答
反对 回复 2023-07-30
  • 3 回答
  • 0 关注
  • 116 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信