Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
返回的数组在PHP中被分配为null变量_Php_Sugarcrm - Fatal编程技术网

返回的数组在PHP中被分配为null变量

返回的数组在PHP中被分配为null变量,php,sugarcrm,Php,Sugarcrm,我在PHP中有一个函数,它调用另一个类函数,以便为它的一个变量$related赋值 需要该值的原始函数使用requestACLForAccess()函数向$headers变量添加特定变量filter: 列表记录功能: public function listRecords($api) { header("Access-Control-Allow-Origin: *"); if ($this->authenticationProcedure() !== false)

我在
PHP
中有一个函数,它调用另一个类函数,以便为它的一个变量
$related
赋值

需要该值的原始函数使用
requestACLForAccess()
函数向
$headers
变量添加特定变量
filter

列表记录
功能:

    public function listRecords($api)
{
    header("Access-Control-Allow-Origin: *");
    if ($this->authenticationProcedure() !== false) {
        $headers = apache_request_headers();
        $access = $this->requestACLForAccess($headers['module'], $headers['oauth_token'], $_SERVER['REQUEST_METHOD']);
        if(gettype($access) == "array"){
        $headers['filter'][0][$access[1]]['$equals'] = $access[2];
        }
        $listObject = new FilterApi();;
        return $listObject->filterList($api, $headers);
    }
}
正在调用的函数
requestACLForAccess

protected function requestACLForAccess(
    $targetModule,
    $token,
    $req_type,
    $getSpecialFlag = false,
    $targetId = null
) {
    $row = $this->checkTokenValid("token", $token);
    if (!empty($row) || $row !== false) {
        $related = \Sugarcrm\Sugarcrm\custom\clients\base\CustomACL::checkRelated($row['module'], $targetModule, $row['id'], $req_type, $getSpecialFlag, $targetId);
        die(gettype($related)); // For debugging
        return $related;
    }
    else {
        return false;
    }
}
调用的函数位于另一个名为
customACL.php
的文件中。在该函数中,某个条件语句返回一个
数组$arr
,该数组应分配给上述特定变量。正在调用的函数:

    public static function checkRelated($module, $targetModule, $id, $req_type, $getSpecial, $targetId)
{
  $bean = \BeanFactory::retrieveBean($module, $id);
  if($bean->designation == self::ADMIN_NAME && !(in_array($targetModule, self::RECORD_RELATION_MODULES))){
    return self::ACL_ADMIN;
  } else{
    //first check if a relational table between modules exists
    $query = "select table_name from information_schema.tables where table_name like '%{$module}%{$targetModule}%' OR table_name like '%{$targetModule}%{$module}%'";
    $result = $GLOBALS['db']->query($query);
    $row = $result->fetch_assoc();
    if (empty($row)) { //if no table exists
       return self::ACL_ADMIN;
    } else { //find out table name
        $table_name = $row['table_name'];
        if ($req_type == 'PUT' || $req_type == 'DELETE' || $req_type == 'GET') { //check if record has relation
        $acl_access = self::checkRecordRelated($table_name, $id, $module, $req_type, $targetId, $targetModule);
      }
    }
  }
}
对于我的特定调用,此函数随后转到同一文件中的
checkRecordRelated()
函数:

  protected static function checkRecordRelated($table_name, $id, $module, $req_type, $targetId, $targetModule)
{
    //find out module column name in relational table
    $query = "select column_name from information_schema.columns where table_name = '$table_name' and column_name like '%{$module}_id%' or column_name like '%{$module}s_id%'";
    $result = $GLOBALS['db']->query($query);
    $row = $result->fetch_assoc();
    if (empty($row)) {//if no column name
        return self::ACL_NON_ADMIN;
    } else {//return module column name
        $column_name = $row['column_name'];
    }

    if ($req_type == 'GET') {//if special GET request
        //find if related records exist in relational table for listing
        $findRelatedRecords = "select * from $table_name where $column_name = '$id' and 'deleted' = 0";
        $result = $GLOBALS['db']->query($findRelatedRecords);
        $row = $result->fetch_array();
        if (empty($row)) {//if NON_ADMIN exist
            return self::ACL_NON_ADMIN;
        } else {//if exist
            $arr = array(self::ACL_ADMIN, $table_name, $id);
            return $arr;
        }
    }
  }
}
在我定义变量
$arr
之前,使用
gettype()
检查会返回一个数组,并且打印该变量会(如预期的那样)为我提供一个包含已添加值的完整数组。但是,一旦值返回到原始函数并分配给变量
$related
,数组就会以某种方式变为
NULL
,gettype()也会返回
NULL

更新:我添加了缺失的函数以使其更清晰,我希望它有意义


谁能告诉我我在这里犯了什么天真的错误?为什么会这样

这很尴尬,我忘了在
checkrelated()
函数中返回
$aclacess
变量,这就是它显示为null的原因。添加返回值是解决方案。

我看不出两个代码片段之间的关系。在哪里调用
requestACLForAccess
?另外,“请注意这一点”不够准确。“那些不应该发生的事情到底发生了什么?”杰托更新了这个问题。希望现在更容易理解