【问题标题】:How to solve Oscommerce, Warning: sizeof(): Parameter must be an array or an object that implements CountableOscommerce如何解决,警告:sizeof(): Parameter must be an array or an object that implement Countable
【发布时间】:2020-11-02 08:46:39
【问题描述】:

我安装了最新版本的 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;
  }

【问题讨论】:

    标签: php oscommerce


    【解决方案1】:

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

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

    它解决了我的错误

    【讨论】:

      【解决方案2】:

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

      if (empty($cPath_array)) { }
      

      代替

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

      【讨论】:

        【解决方案3】:

        sizeofcount 的别名。

        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
        

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

        错误的临时解决方案: 降级你的 PHP 版本。

        【讨论】:

          猜你喜欢
          • 2018-11-01
          • 2023-01-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-10-06
          • 2012-04-22
          • 2023-03-20
          相关资源
          最近更新 更多