首页 > 解决方案 > 如何修复:警告:第 140 行 F:\xampp\htdocs\digikalamvc\core\model.php 中的非法偏移类型或为空

问题描述

如何修复此错误:

警告:isset 中的非法偏移类型或 F:\xampp\htdocs\digikalamvc\core\model.php 第 140 行为空

致命错误:未捕获错误:F:\xampp\htdocs\digikalamvc\models\model_showcart4.php:90 中不支持的操作数类型 堆栈跟踪:#0 F:\xampp\htdocs\digikalamvc\controllers\showcart4.php(31): model_showcart4 ->saveOrder(Array) #1 F:\xampp\htdocs\digikalamvc\core\app.php(34): Showcart4->saveorder() #2 F:\xampp\htdocs\digikalamvc\index.php(7): App->__construct() #3 {main} 在第 90 行的 F:\xampp\htdocs\digikalamvc\models\model_showcart4.php 中抛出

第 140 行 model.php 中的代码:(if (isset($_SESSION[$name])) {

public static function sessionGet($name) {
    if (isset($_SESSION[$name])) {
        return $_SESSION[$name];
    } else {
        return false;
    }
}

第 90 行 model_showcart4.php 中的代码:

$priceTotal =$basketPrice-$basketDiscount+$postprice;

代码model_showcart4:

$basket = $basketInfo[0];
    $basket = serialize($basket);
    $basketPrice = $basketInfo[1];
    $basketDiscount = $basketInfo[2];

    $postprice = $this->calculatePostPrice($addressInfo['city']);
    $postType = self::sessionGet(['postType']);
    if ($postType == 1) {
        $postprice = $postprice['pishtaz'];
    } elseif ($postType == 2) {
        $postprice = $postprice['sefareshi'];
    }

    $priceTotal =$basketPrice-$basketDiscount+$postprice;

第 31 行的代码 showcart4.php:

function saveorder() {
    $this->model->saveOrder($_POST);
}

标签: phpsessionxamppoffset

解决方案


$postType = self::sessionGet(['postType']); 如您所见,参数是一个数组。所以这里 isset($_SESSION[$name])的代码变得无效,因为数组键应该是整数或字符串,而不是数组。

$postType = self::sessionGet('postType');- 这应该可行,我猜


推荐阅读