<?php const DIRECTORY_PATH = '/var/www/'; class FileNotFoundException extends \Exception { } function getFiles(string $directory) { // trying getting files /** *if (isFile($directory)) { * throw new \Exception("First argument of getFiles must be a directory, not a file."); *} */ throw new FileNotFoundException("Files in $directory not founded."); // или может быть, тебе не сильно важно, найдет ли он файлы, можешь возвращать пустой массив // кучу вариантов короче) } // smth... try { $fileList = getFiles(DIRECTORY_PATH); } catch (FileNotFoundException $e) { echo $e->getMessage(); // обрабатывай в зависимости от того, что тебе нужно =) // можешь присвоить пустой массив $fileList = []; }
You have javascript disabled. You will not be able to edit any code.