2017-10-14 85 views
0

得到一个错误PHP的警告:非法串在../roundcube/plugins/vtrc/vtwsclib/Vtiger/WSClient.php偏移“错误”上线93PHP的警告:非法串偏移“错误” roundcube插件

在PHP文件(行93两端)

function hasError($result) { 
     if(isset($result[success]) && $result[success] === true) { 
      $this->_lasterror = false; 
      return false; 
     } 
     $this->_lasterror = $result[error]; 
     return true; 
+0

我猜你需要添加引号,所以数组访问会是什么样'$结果[“错误”]'或'$结果[“成功”]' –

+0

如果'error'是你需要一个字符串使用引号或双引号 – frz3993

回答

0

您有两个重要错误!

首先的:你需要使用“或”获取数组

$value = $array["KEY_HERE"]; 

Same as 
$value = $array['KEY_HERE']; 

PHP是用引号友好的价值=)


:您需要检查“错误”键是否存在Array $结果中,如“成功”

function hasError($result) { 
    if(isset($result["success"]) && $result["success"] === true) { 
     ... CODE ... 
    } 
    if(isset($result["error"])) { 
     ... CODE ... 
    } 
    ... REST OF METHOD ... 
} 

这是什么意思“非法字符串偏移'错误'?确切地说,不存在数组$结果的索引'错误'。请小心,因为脚本试图访问未声明(初始化 - 设置)的数组。这很危险 !!

$myArray = array();    /** Empty array **/ 
$myArray["error"] = "";   /** set index "error" with "" value **/ 

echo isset($myArray["error"]);  /** echo TRUE **/ 
echo isset($myArray["success"]); /** echo FALSE **/ 
echo $myArray["success"];   /** throw exception "Illegal string offset 'success' ..." because not set in Array **/ 
0
当你试图让用绳子关联数组的索引

功能失调添加"'的偏移。将您的功能更改为

function hasError($result) { 
     if(isset($result["success"]) && $result["success"] === true) { 
      $this->_lasterror = false; 
      return false; 
     } 
     $this->_lasterror = $result["error"]; 
     return true; 
相关问题