Cannot assign an empty string to a string offset

后端 未结 4 531
走了就别回头了
走了就别回头了 2021-01-21 02:33

I\'ve just installed PHP 7.1 and now I am seeing this error :

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


        
相关标签:
4条回答
  • 2021-01-21 03:00

    It's because you want to unset a string at the first element. just use substr($fDomains, 1);

    0 讨论(0)
  • 2021-01-21 03:00

    My reason for this message 'PHP Warning: Cannot assign an empty string to a string offset' is: My $fDomains variable was initiated as a string, not as an array.

    0 讨论(0)
  • 2021-01-21 03:03

    According to bug #71572 it's not permitted to assign 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 讨论(0)
  • 2021-01-21 03:04

    Either ($fDomains = "";) or ($fDomains[0] = "";) is wrong, but without seeing the rest of the code, it's impossible to say which is wrong.

    If $fDomains is a string, then the assignment $fDomains='' will empty its contents. If $fDomains is an array, it should be initialized as $fDomains=array() instead of $fDomains="", and $fDomains[0]='' is the correct way to clear the string value of the first element in the array.

    Actually, both of the assignments you illustrated in your comment (as reproduced at the top of this answer) are wrong - there shouldn't be a semicolon (;) at the end of the parenthesized expression, and unless you have a string that PHP needs to interpret (e.g., for embedded variables or escape sequences), you should use single quotes instead of double quotes - =""; should be =''.

    0 讨论(0)
提交回复
热议问题