php - 如何修复:警告:第 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);
}
解决方案
$postType = self::sessionGet(['postType']);
如您所见,参数是一个数组。所以这里
isset($_SESSION[$name])
的代码变得无效,因为数组键应该是整数或字符串,而不是数组。
$postType = self::sessionGet('postType');
- 这应该可行,我猜
推荐阅读
- docker - 使用 Go 部署 Docker 的问题
- r - 如何使用 Windows 10 和 R 3.4.4 安装和调用包“multidplyr”
- php - PHP连接到数据库失败且没有错误
- excel - 循环使用白色填充的所有单元格并将它们更改为无填充
- html - 如何在 Dreamweaver 中的 HTML 电子邮件模板中的背景图像上方的图像上去掉 X?
- python - Tkinter:Win check in 可扩展井字游戏不起作用
- java - 检查 jpanel 上的某个区域是否涂有东西
- c++ - 将行表单文件与 cout 中的自定义文本组合的问题
- c++ - 在工厂或 C++ 的类中包含数据库 .h 文件
- scala - 如果类和对象在同一个文件中,如何调用类构造函数