I would like to test if the function array_map('unlink', glob('...*.txt')) did not encounter an error: ex.:
try {
array_map('unlink', glob('/folder/my_files--*.txt'));
}
catch (\Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
In your opinion, does this code seem valid? Thank you for your feedback !
No, none of these function throw an exception, so no exception will ever be caught by this code.
unlinkreturnstrueorfalse, so the result ofarray_mapwill be an array oftrueand/orfalsevalues, and you need to test whether all values in the array aretrueto know whether allunlinkoperations succeeded.For this kind of operation,
array_reduceis actually the better option, as it allows you to reduce the result to a single value right while you're iterating: