7

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.

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
TopMTV
  • 81
  • 1
  • 1
  • 3
  • 1
    Your second code (when you use `[ ]` instead of `{ }`) is the way to go as `{ }` is deprecated as the previous notice shows... and you also never had to use `{ }` but always `[ ]` when you are accessing an `array`... So change your code to `[ ]` and when you get error `500`, see the logs and share them with us... – matiaslauriti Aug 26 '21 at 02:32
  • Thanks all, this code don't run with php8 – TopMTV Aug 28 '21 at 06:27
  • The change from `{}` to `[]` is all that's needed to work with PHP 8. If your code doesn't work, the problem is probably somewhere else and there's nothing else we can do until you share some information about the error you're experiencing. – nxasdf Apr 16 '22 at 00:48

1 Answers1

13

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

enter image description here

lava
  • 6,020
  • 2
  • 31
  • 28
JPT
  • 410
  • 2
  • 7
  • 18