问题背景
因为迁移了服务器,遂将Typecho1.2.0应用环境php7.2升级到了php7.4,博客使用没啥大问题。晚上在浏览博客的小程序时候发现出了图片,文字内容都不能显示,猜测可能是api出了问题,小程序端无法读取json输出,于是浏览器打开api查看发现确实是php报错了"Warning: Use of undefined constant"
经过一番检索,发现这篇文章作者(浩瀚博客)与我相同情况,经过测试问题已得到解决。

解决办法
1.开启typecho的debug模式

编辑typecho 目录下的

config.inc.php

在文件中增加下面一行代码后保存文件

define('__TYPECHO_DEBUG__', TRUE);

2.在相应路径查看并编辑报错的文件

$post[0]['thumb'] =  $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $cid)->where('name = ? ',thumb))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $cid)->where('name = ? ',thumb)):array(array("str_value"=>$thumb));

在php中出现这个错误信息,通常是没有明确类型,上一行代码中的 thumb 前面没有 $ ,表示它不是一个变量,它没有” 或者’包裹表示thumb 它也不是一个常量,最后php就会给出 undefined constant 这样的报错。
这样的报错只是在php7+中关闭报错的话可以继续执行,而php8.0不行。

3.修复问题
依次搜索常量(或批量替换),例如我这里搜索的是, thumb , 替换字符为 , 'thumb',我们用'来包裹它

$post[0]['thumb'] =  $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $cid)->where('name = ? ','thumb'))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $cid)->where('name = ? ','thumb')):array(array("str_value"=>$thumb));

将报错的字段一一进行搜索替换用'进行包裹,再刷新一下网页,无报错即解决问题。

参考文章:
[1] php 出现"Warning: Use of undefined constant"的解决方法
[2] 升级php8.0后出现‘Warning: Use of undefined constant’报错的问题