我有一個函數,PHP它調用另一個類函數以便為它的一個變量賦值$related。需要該值的原始函數使用該requestACLForAccess()函數將特定變量添加filter到$headers變量中:listRecords功能: 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. 在該函數中,某個條件語句返回一個array $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; } 直到我定義了變量$arr,檢查gettype()返回一個數組并打印變量給我(如預期的那樣)一個完整的數組,其中包含我添加的值。但是,一旦將值返回給原始函數并分配給變量$related,數組就會以某種方式變為NULL并且 gettype() 也返回NULL。更新:我添加了缺少的功能以使其更清晰,我希望它有意義誰能告訴我我在這里犯了什么天真的錯誤?為什么會這樣?
1 回答

慕標5832272
TA貢獻1966條經驗 獲得超4個贊
好吧,這很尷尬,我忘了在函數中返回$aclaccess
變量,checkrelated()
這就是它顯示 null 的原因。添加返回值是解決方案。
- 1 回答
- 0 關注
- 101 瀏覽
添加回答
舉報
0/150
提交
取消