Is this conditional check overkill?

JohnH

New Member
\[code\]$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}\[/code\]The function validateUploadedFile returns an array as $result['valid'] == TRUE if it goes through.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.\[code\]if ( $result['valid'] ){ // do sth}\[/code\]Thank you\[code\]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;}\[/code\]
 
Back
Top