Can't assign empty string to string offset

I just installed PHP 7.1 and now I see this error:

PHP Warning:  Cannot assign an empty string to a string offset in /postfixadmin/variables.inc.php on line 31

      

Line No. 31:

$fDomains[0] = "";

      

How do I now clear $ fDomains [0] in PHP 7.1?

+3


source to share


3 answers


This is because you want to reverse the line in the first element. just usesubstr($fDomains, 1);



+2


source


As per bug # 71572 it is not allowed to assign an empty string. Then use:

substr(fDomains,1); //like Kris Roofe wrote;

      



or use solutions like this:

$fDomainsTmp = $fDomains;
for($x = 0 ; $x < length($fDomains); $x ++){
    if(condition character allow in string){ 
      $fDomainsTmp .= $fDomains[$x]; 
    }
}
$fDomains = $fDomainsTmp;

      

0


source


Either ($fDomains = "";)

it ($fDomains[0] = "";)

is wrong, but without seeing the rest of the code, it is impossible to tell that it is wrong.

If $fDomains

is a string, then the assignment will $fDomains=''

empty its contents. If $fDomains

is an array, it must be initialized $fDomains=array()

instead of $fDomains=""

, and $fDomains[0]=''

is the correct way to clear the string value of the first element of the array.

In fact, both of the assignments you illustrated in your comment (as reproduced at the top of this answer) are wrong - there should be no semicolon ( ;

) at the end of the parenthesized expression, and unless you have a string that PHP should interpret ( e.g. for built-in variables or escape sequences), you should use single quotes instead of double quotes - should be . ="";

=''

0


source







All Articles