Bu koşullu onay overkill mi?

0 Cevap
$result = validateUploadedFile($_FILES);

if (!empty($result) && !empty($result['valid']) && $result['valid'])
{
    // do sth
    // I don't know why sometime this three checks will cause me problems
    // In other words, even if $result['valid'] is TRUE, this scope will not be hit
}

ValidateUploadedFile $ sonucunda bir dizi döndüren işlevi ['geçerli'] == o geçer DOĞRU eğer.

Here is the question, does the if statement checks too much? Can I simply check the following instead? I have few PHP language knowledge and don't know whether those checks are necessary or not.

if ( $result['valid'] )
{
    // do sth
}

Teşekkür ederim

function validateUploadedFile($uploadedFile)
{
    // Define file size limit
    $result = array('valid' => FALSE, 'error_message' => null, 'error_code' => null);

    if (sth_wrong)
    {
      $result['error_message'] = 'sth_wrong';
      return $result;    
    }

    if (sth_wrong2)
    {
      $result['error_message'] = 'sth_wrong2';
      return $result;    
    }    

    $result['valid'] = TRUE;
    return $result;
}

0 Cevap