Search code examples
phpsessionxamppoffset

How to fix: Warning: Illegal offset type in isset or empty in F:\xampp\htdocs\digikalamvc\core\model.php on line 140


How to fix this error:

Warning: Illegal offset type in isset or empty in F:\xampp\htdocs\digikalamvc\core\model.php on line 140

Fatal error: Uncaught Error: Unsupported operand types in F:\xampp\htdocs\digikalamvc\models\model_showcart4.php:90 Stack trace: #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} thrown in F:\xampp\htdocs\digikalamvc\models\model_showcart4.php on line 90

Code in model.php on line 140: ( if (isset($_SESSION[$name])) { )

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

Code in model_showcart4.php on line 90:

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

Code 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;

Code showcart4.php on line 31:

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

Solution

  • $postType = self::sessionGet(['postType']); as you can see, argument is an array. so here isset($_SESSION[$name]) code gets to be invalid, because array key should be integer or string, not an array.

    $postType = self::sessionGet('postType'); - this should work, I guess