Search code examples
phpmigrationphp-5.3php-8

Migration to PHP8


I have code from old PHP. But when I tried to execute it by PHP 8.

The first code was:

PasteBin

I had error:

Fatal error: Array and string offset access syntax with curly braces is no longer supported in **** on line 550

On line:

for ($i = 0; $i < strlen($text); $i++) $res .= ord($text{$i}) . "-";

I changed it to:

for ($i = 0; $i < strlen($text); $i++) $res .= ord($text[$i]) . "-";

But I had another error:

Warning: Trying to access array offset on value of type bool in *** on line 76

On line:

$real = $row['sip'];

I have no idea - how to rewrite this string.
Can you help me?


Solution

  • the problem is that you are trying to access a boolean value as you do with an array.

    i imagine that $row is the result of a query, and that query does not return any matching rows, so it's false.

    just check if $row is false before you access it.

    <?php
    $row = false;
    echo $row['test'];
    

    this returns that warning.

    as per your comment, it depends on what you wanna do.

    if it exist return the values, if it doesn't?

    if($row){
    // if it contains something, do something with it
    }else{
    // do something else if it doesn't
    }
    

    i don't know what's the flow of your code, so I can't really help you, it's just a check to see if the $row variable is not false