惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
人人都是产品经理
人人都是产品经理
H
Heimdal Security Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
雷峰网
雷峰网
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog
A
About on SuperTechFans
V2EX - 技术
V2EX - 技术
小众软件
小众软件
博客园 - Franky
博客园 - 司徒正美
P
Privacy International News Feed
爱范儿
爱范儿
U
Unit 42
博客园 - 叶小钗
The Hacker News
The Hacker News
C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Simon Willison's Weblog
Simon Willison's Weblog
N
News and Events Feed by Topic
D
Docker
T
Threatpost
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Help Net Security
L
LINUX DO - 最新话题
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
S
SegmentFault 最新的问题
A
Arctic Wolf
Spread Privacy
Spread Privacy

博客园 - Tinywan

Ubuntu 22.04 编译安装 PHP 7.4.33 报错:make: *** [Makefile:749: ext/openssl/openssl.lo] Error 1 how to set mpdf HTML contains invalid UTF-8 character(s) 和 CPU 100% Redis Docekr WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition Nginx添加第三方模块,出现“is not binary compatible in”错误的解决方案 Docker 数据库连接见解异常 SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again 解决mysql死锁问题 SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction Java系列 | 如何讲自己的JAR包上传至阿里云maven私有仓库【云效制品仓库】 Redis系列 | 分类树查询功能如何从2s优化到0.1s Docker系列 | docker endpoint for “default” not found Node系列 | Node版本管理工具 fnm Java系列 | IntelliJ IDEA 如何导入和使用一个Jar包 Chrome扩展插件:Console Importer(控制台导入器) PHP系列 | mPdf字体库异常 Cannot find TTF TrueType font file "Eeyek.ttf" in configured font directories PHP系列 | PHP中的stdClass是什么? 网络安全 | 记录一次acme.sh更新证书 Error add txt for domain:_acme-challenge.tinywan.com 大数据系列 | 阿里云datav数据可视化(使用json文件生成可视化动态图标) Docker系列 | SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again768 Java系列 | Linux系统中运行JMeter脚本 PHP系列 | TP6使用表达式设置数据 Db::raw('end_time')
响应错误: Indirect modification of overloaded element of app\model\StudentCacheModel has no effect - Tinywan
Tinywan · 2026-03-11 · via 博客园 - Tinywan

报错信息

•  请求路由:/student/v2/users/info
•  响应错误: Indirect modification of overloaded element of app\common\model\StudentCacheModel has no effect

这个报错:

Indirect modification of overloaded element of app\common\model\StudentCacheModel has no effect

是 PHP 的一个经典 Notice(有时也会被提升为 Warning 或 Error,取决于错误报告级别),几乎只出现在 ThinkPHP 项目中(因为你用了 app\common\model\ 这种标准的 TP 命名空间)。

核心原因(一句话总结)

你拿到的是通过 __get() 魔法方法返回的临时值(通常是一个数组),然后你试图直接修改这个临时数组,PHP 不允许这样操作,所以报错,而且修改根本不会生效

最常见的几种写法都会触发这个错误:

// 情况1:最常见
$student = StudentCacheModel::get($id);
$student['some_field'][] = 'new value';          // ← 报错

// 情况2:多级数组修改
$student['config']['level'] = 10;                 // ← 报错

// 情况3:foreach 里直接改
foreach ($student['tags'] as &$tag) { ... }       // ← 也可能报

为什么会这样?

ThinkPHP 的模型(继承自 think\Model)在你用 $model['field'] 这种数组方式访问时,实际上是通过 __get() 魔法方法返回的:

  • 第一次 $model['field'] → 调用 __get('field') → 返回一个拷贝(或新构造的值)
  • 你再去改 $model['field']['xxx'] = yyy → 你改的是临时拷贝,不是模型内部的数据
  • 所以 PHP 报 “indirect modification ... has no effect”(间接修改重载元素无效)

正确写法(几种解决方案,按推荐顺序)

最推荐:先取出来,改完再赋值回去(最清晰、安全)

$student = StudentCacheModel::get($id);

// 取出
$data = $student['some_field'];           // 或 $student->some_field
$data[] = 'new value';

// 写回去
$student['some_field'] = $data;           // 或 $student->some_field = $data
// 或者直接用属性方式(如果允许)
$student->some_field = $data;

$student->save();   // 别忘了保存

 正确代码

$gainInfo = $this->model->where([
   'gid' => $this->gid,
   'uid' => $this->uid,
])->findOrEmpty();
if ($gainInfo->isEmpty()) {
   $where = [];
   $where[] = ['course_id','=',$this->courseId];
   $where[] = ['type','=',self::$cacheType];
   $where[] = ['create_user','=',$this->uid];
   $cacheInfo = StudentCacheModel::where($where)->find();
   if ($cacheInfo) {
         $result['content'] = json_decode($cacheInfo['content'],true);
         if (!empty($result['content']['goods_img1']) && is_string($result['content']['goods_img1'])) {
            $result['content']['goods_img1'] = string_to_array($result['content']['goods_img1']);
         }
         if (!empty($result['content']['live_img1']) && is_string($result['content']['live_img1'])) {
            $result['content']['live_img1'] = string_to_array($result['content']['live_img1']);
         }
         if (!empty($result['content']['face_img1']) && is_string($result['content']['face_img1'])) {
            $result['content']['face_img1'] = string_to_array($result['content']['face_img1']);
         }
         $result['is_cache'] = 1;
         return $result;
   } else {
         return $this->setError(false, '不存在');
   }
}