未设定的对象值

时间:2015-06-25 06:27:09

标签: php object unset

我试图取消设置对象的值

我想从对象$docList

取消设置文档编号-950
foreach ($docList as  $document) {
    $visibleOrgIDs = $docList->LoadVisibleOrganizationListByDocID($document->getId());
    if(!in_array($org,$visibleOrgIDs)){
        unset($document->getId());
    }
}

$docList是我正在遍历的对象。 print_r($docList)会导致:

LomsDocumentList Object (
    [offset:protected] => 
    [limit:protected] => 
    [filter:protected] => 
    [sort:protected] => 
    [additionalFields:protected] => 
    [fetchCount] => 
    [countAll] => 
    [objectIds:RosiBaseList:private] => Array
        (
            [0] => 950
        )

    [storage:SplObjectStorage:private] => Array
        (
            [00000000277be4ca0000000108de8355] => Array
                (
                    [obj] => LomsDocument Object
                        (
                            [DBtableFieldNames:protected] => Array
                                (
                                    [id] => DOC_ID
                                    [parentDocumentId] => PARENT_ID
                                    [ownerId] => OWNER_ID
                                    [fileId] => FILE_ID
                                    [linkId] => LINK_ID
                                    [documentTypeId] => DOC_TYPE_ID
                                    [languageId] => LANG
                                    [organizationId] => ORG_ID
                                    [bpDepartmentId] => BP_DEPARTMENT_ID
                                    [elementId] => ELEMENT_ID
                                    [title] => TITLE
                                    [description] => DESCRIPTION
                                    [validUntil] => VALID_UNTIL
                                    [isInternal] => IS_INTERNAL
                                    [isInRevision] => IS_IN_REVISION
                                    [mediaType] => MEDIA_TYPE
                                    [expirationAdviceSent] => EXPIRATION_ADVICE_SENT
                                    [firstAuthorId] => CRT_ID
                                    [lastAuthorId] => LAST_UPDT_ID
                                    [contentOwnerId] => CONTENT_OWNER_ID
                                    [extractDocumentId] => EXTRACT_ID
                                    [sortField] => SORT_FIELD
                                    [category] => CATEGORY
                                    [mediaUpdateAt] => LAST_MEDIA_CHNG_DATE_TIME
                                    [mediaUpdateBy] => LAST_MEDIA_CHNG_NAME
                                )

                            [DBtableName:protected] => LOMS_DOC
                            [parentDocumentId:protected] => 
                            [parentDocument:protected] => 
                            [ownerId:protected] => 174450
                            [owner:protected] => 
                            [fileId:protected] => 4967
                            [file:protected] => 
                            [linkId:protected] => 
                            [link:protected] => 
                            [documentTypeId:protected] => 3
                            [documentType:protected] => 
                            [languageId:protected] => de
                            [language:protected] => 
                            [organizationId:protected] => 122
                            [organization:protected] => 
                            [bpDepartmentId:protected] => 122
                            [bpDepartment:protected] => 
                            [elementId:protected] => 52
                            [element:protected] => 
                            [title:protected] => Testdokument_1_New_BF_BENE_20.11.2014
                            [description:protected] => Test OMS BF Finance BeNe
                            [validUntil:protected] => DateTime Object
                                (
                                    [date] => 2014-12-19 00:00:00.000000
                                    [timezone_type] => 3
                                    [timezone] => Europe/Berlin
                                )

1 个答案:

答案 0 :(得分:0)

您可以在LomsDocumentList类中创建一个使用array_search函数取消设置变量objectIds的方法。

示例:

class LomsDocumentList {
    public function searchAndUnsetByValue($val) {
        $key = array_search($val, $this->objectIds);
        if ($key !== FALSE) {
            unset($this->objectIds[$key]);
        }
    }
}

并将其命名为

$docList->searchAndUnsetByValue(950);