Curly braces is deprecated and Parameter must be an array or an object that implements Countable

What should be modified to solve PHP warning:
Array and string offset access syntax with curly braces is deprecated

                    $bad = (ord($data{$x}) > 127);

and
Parameter must be an array or an object that implements Countable

    if(count($attachments) > 0){

Use square brackets [] instead of curly braces {}.

Whatever $attachments is, it’s not a countable object.

The error regarding $attachments is most likely caused by an uninitialized array. The best way to solve is to initialize to an empty array before using it in any way.

Do you think it will work? Thank you for the message.

$attachments = (array) null;

To initialize would just be $attachments = [];

I have tested. It is working. Thank you for all explanations. You are excellent developers.

$attachments = (array) null;

But your will be empty of all values inside the form:

$attachments = [];

The idea is to initialise it at the beginning, so values may be added from the form (or wherever values come from) after initialisation.
That way is will still be an array (and countable) even if it is still empty at the end, with no values added.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.