fastadmin thinkphp5.0 支持php8.1 以上版本

   PHP8 的兼容性主要在以下几点:

1. 部分函数的返回值问题

2. 字符串函数的 NULL 传值问题

此次修改可以让 FASTADMIN 支持使用 PHP8.1 、PHP8.2 

\thinkphp\library\think\Template.php:894

parseVarFunction 中增加对 tpl_denynull_str_func_list 中定义的字符串函数进行判断,处理 NULL
 

    /**
     * 对模板中使用了函数的变量进行解析
     * 格式 {$varname|function1|function2=arg1,arg2}
     * @access public
     * @param  string $varStr 变量字符串
     * @return void
     */
    public function parseVarFunction(&$varStr)
    {
		// if(strpos($varStr,'htmlentities')>0){
			// var_dump('2:'.$varStr);}
			
        if (false == strpos($varStr, '|')) {
            return;
        }
		
		$template_denynull_funs = explode(',', $this->config['tpl_denynull_str_func_list']);

			
        static $_varFunctionList = [];
        $_key                    = md5($varStr);
        //如果已经解析过该变量字串,则直接返回变量值
        if (isset($_varFunctionList[$_key])) {
            $varStr = $_varFunctionList[$_key];

        } else {
            $varArray = explode('|', $varStr);
            // 取得变量名称
            $name = array_shift($varArray);
			

			
            // 对变量使用函数
            $length = count($varArray);
            // 取得模板禁止使用函数列表
            $template_deny_funs = explode(',', $this->config['tpl_deny_func_list']);
            for ($i = 0; $i < $length; $i++) {
                $args = explode('=', $varArray[$i], 2);
                // 模板函数过滤
                $fun = trim($args[0]);
								
                switch ($fun) {
                    case 'default': // 特殊模板函数
                        if (false === strpos($name, '(')) {
                            $name = '(isset(' . $name . ') && (' . $name . ' !== \'\')?' . $name . ':' . $args[1] . ')';
                        } else {
                            $name = '(' . $name . ' ?: ' . $args[1] . ')';
                        }
                        break;
                    default: // 通用模板函数
                        if (!in_array($fun, $template_deny_funs)) {
                            if (isset($args[1])) {
                                if (strstr($args[1], '###')) {
                                    $args[1] = str_replace('###', $name, $args[1]);
                                    $name    = "$fun($args[1])";
                                } else {
									if (in_array($fun, $template_denynull_funs)) {
										$name = "$fun($name ?? '',$args[1] ?? '')";		//bylyf 202308
									}else{
										$name = "$fun($name,$args[1])";
									}
                                }

                            } else {
                                if (!empty($args[0])) {
									if (in_array($fun, $template_denynull_funs)) {
										$name = "$fun($name ?? '')";		//bylyf 202308
									}
									else{
										$name = "$fun($name)";
									}

                                }

                            }
                        }
	
                }
            }
			

			
            $_varFunctionList[$_key] = $name;
            $varStr                  = $name;
        }
        return;
    }


\thinkphp\library\think\template\taglib\Cx.php:361

tagRange 函数中对  explode 函数加上检测是否是 NULL


\thinkphp\library\think\Collection.php 中多个函数加上 #[\ReturnTypeWillChange]

以下文件都被修改过:
\thinkphp\library\think\Template.php
\thinkphp\library\think\Url.php
\thinkphp\library\think\Config.php
\thinkphp\library\think\Paginator.php
\thinkphp\library\think\Collection.php
\thinkphp\library\think\Request.php
\thinkphp\library\think\Model.php
\thinkphp\library\think\db\Query.php
\thinkphp\library\traits\controller\Jump.php
 

下载地址:https://download.csdn.net/download/ilyf2005/88178122

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值