Extra Form
PHP PHP 7.2
CMS Rhymix

widgets/newest_document/newest_document.class.php:75

 

그동안 댓글에서 봤던 패던과 달라서 뭐가 문제인지 모르겠습니다.

 

 

 

            // 결과가 있으면 각 문서 객체화를 시킴
            $modules = array();
            if(count($output->data)) {
                foreach($output->data as $key => $attribute) {
                    $modules[$attribute->module_srl]->mid = $attribute->mid;  // 에디터상 75번 라인은 여기입니다.
                    $modules[$attribute->module_srl]->site_srl = $attribute->site_srl;

                    $document_srl = $attribute->document_srl;

                    $oDocument = null;
                    $oDocument = new documentItem();
                    $oDocument->setAttribute($attribute, false);
                    $GLOBALS['XE_DOCUMENT_LIST'][$oDocument->document_srl] = $oDocument;

                    $document_list[$key] = $oDocument;
                }
                $oDocumentModel->setToAllDocumentExtraVars();
            } else {

                $document_list = array();
                
            }

  • profile

    맨 꼭대기에 보면 $modules는 비어 있습니다.

     

    $modules[$attribute->module_srl] 이 선언되지 않은 상태에서

    $modules[$attribute->module_srl]->mid 를 만들려고 했네요.

     

    이 경우에는 워닝이 발생하는 줄 바로 위에서

    $modules[$attribute->module_srl] = new stdClass; 라고 선언하면 됩니다.

    문법이 복잡해 보여도 그냥 저 대괄호로 묶인 부분까지 모두 하나의 변수라고 취급하시면 됩니다.

     

    단, 루프를 한 번 돌 때마다 new stdClass로 초기화되기 때문에

    루프를 여러 번 돌면서 데이터를 차곡차곡 쌓아야 하는 경우에는 이 팁이 적절하지 않을 수 있습니다.

    (이런 경우에는 해당 변수가 있는지 없는지 먼저 체크한 후, 없을 때만 초기화하도록 해야 합니다.)

    올려주신 코드는 그런 경우가 아니므로 위와 같이 무조건 초기화시켜도 무방합니다.

  • profile profile
    어.. 이거 루프 안쪽의 코드만 게시한 것 이었습니다.

    // 결과가 있으면 각 문서 객체화를 시킴
    $modules = array();
    if(count($output->data)) {
    foreach($output->data as $key => $attribute) {
    $modules[$attribute->module_srl]->mid = $attribute->mid;
    $modules[$attribute->module_srl]->site_srl = $attribute->site_srl;

    $document_srl = $attribute->document_srl;

    $oDocument = null;
    $oDocument = new documentItem();
    $oDocument->setAttribute($attribute, false);
    $GLOBALS['XE_DOCUMENT_LIST'][$oDocument->document_srl] = $oDocument;

    $document_list[$key] = $oDocument;
    }
    $oDocumentModel->setToAllDocumentExtraVars();
    } else {

    $document_list = array();

    }


    이게 실제 전체 코드 입니다.
  • profile profile
    뭐 상관없을 것 같습니다. 위에서 깔끔하게 $module를 초기화해주고 있으니까 그 다음 단계를 초기화하는 데도 부담이 없네요.
  • profile profile
    감사합니다. 그럼 처음 말씀하신대로 워닝 라인 바로 위에 넣겠습니다.