Skip to content

php 8.5 无法使用验证码?imagedestroy(); 已经放弃了 #84

Description

@baoxiaolong1

你遇到的这个提示并不是代码报错,而是 PHP 8.5+ 版本的一个弃用警告。
在 PHP 8.0 之前,GD 图像处理使用的是“资源(resource)”类型,必须手动调用 imagedestroy() 来释放内存。但从 PHP 8.0 开始,GD 扩展全面转向了对象(Object)机制,imagedestroy() 实际上已经变成了一个空操作(NOP),不再起任何作用。因此,PHP 官方决定从 8.5.0 版本起正式废弃该函数

8.5 报错信息
Function imagedestroy() is deprecated since 8.5, as it has no effect since PHP 8.0

        $angle = $this->math ? 0 : mt_rand(-40, 40);

        imagettftext($this->im, (int) $this->fontSize, $angle, (int) $x, (int) $y, $this->color, $fontttf, $char);
    }

    ob_start();
    // 输出图像
    imagepng($this->im);
    $content = ob_get_clean();
    imagedestroy($this->im);

    // API调用模式
    if ($this->api) {
        return [
            'code' => implode('', $text),
            'img'  => 'data:image/png;base64,' . base64_encode($content),
        ];
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions