Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array and string offset access syntax with curly braces is deprecated [duplicate]

Tags:

php

php-7.4

People also ask

How do you fix deprecated array and string offset access syntax with curly braces is deprecated in?

PHPCompatibility 7.4 : Array and string offset access syntax with curly braces is deprecated in PHP 7.4. Use square brackets instead.

Could not send email Array and String offset access syntax with curly braces is deprecated?

The error means that somewhere in your code (app, framework, packages) an array key is being referenced by using curly braces (which has been deprecated in PHP 7.4 or greater). You should use brackets instead.


It's really simple to fix the issue, however keep in mind that you should fork and commit your changes for each library you are using in their repositories to help others as well.

Let's say you have something like this in your code:

$str = "test";
echo($str{0});

since PHP 7.4 curly braces method to get individual characters inside a string has been deprecated, so change the above syntax into this:

$str = "test";
echo($str[0]);

Fixing the code in the question will look something like this:

public function getRecordID(string $zoneID, string $type = '', string $name = ''): string
{
    $records = $this->listRecords($zoneID, $type, $name);
    if (isset($records->result[0]->id)) {
        return $records->result[0]->id;
    }
    return false;
}