简体   繁体   中英

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

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

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.

Simply replace {} with []

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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