简体   繁体   English

致命错误:php 8.0 pkcs5_unpad 不再支持带花括号的数组和字符串偏移访问语法

[英]Fatal error: Array and string offset access syntax with curly braces is no longer supported in php 8.0 pkcs5_unpad

I got this error after copying code from a tutorial.从教程中复制代码后出现此错误。 It's deprecated and I tried resolving it:它已被弃用,我尝试解决它:

Array and string offset access syntax with curly braces is no longer supported in.../app/Http/Helpers/helpers.php .../app/Http/Helpers/helpers.php 中不再支持带有花括号的数组和字符串偏移访问语法

My code copy:我的代码副本:

if (!function_exists("pkcs5_unpad_e")) {
    function pkcs5_unpad_e($text) {
        $pad = ord($text{strlen($text) - 1});
        if ($pad > strlen($text))
            return false;

        return substr($text, 0, -1 * $pad);
    }
}

My edit: replace {....} with [.....] ==> HTTP ERROR 500我的编辑:用[.....] ==> HTTP ERROR 500 替换{....}

if (!function_exists("pkcs5_unpad_e")) {
    function pkcs5_unpad_e($text) {
        $pad = ord($text[strlen($text) - 1]);
        if ($pad > strlen($text))
                return false;
            
        return substr($text, 0, -1 * $pad);
    }
}

I am using Ubuntu 20.04 DigitalOcean Cyberpanel server and PHP 8.我正在使用 Ubuntu 20.04 DigitalOcean Cyberpanel 服务器和 PHP 8。

Simply replace {} with []只需将 {} 替换为 []

PS. PS。 No idea why nobody creates an answer instead of a comment.不知道为什么没有人创建答案而不是评论。 So please mark this question solved.因此,请将此问题标记为已解决。

PPS.聚苯乙烯。 I mark this answer community, because I don't want points for a solution provided by someone else.我标记了这个答案社区,因为我不想要别人提供的解决方案的分数。

Look your console error and modify it查看您的控制台错误并修改它

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM